Aquarius_Girl
Aquarius_Girl

Reputation: 22926

What is the return type of List.generate of Flutter when no type is specified?

From: https://flutter.dev/docs/cookbook/navigation/passing-data

final todos = List.generate(
  20,
  (i) => Todo(
    'Todo $i',
    'A description of what needs to be done for Todo $i',
  ),
);

This says a type has to be there: https://api.flutter.dev/flutter/dart-core/List/List.generate.html

What is the return type of List.generate of Flutter when no type is specified?

Upvotes: 0

Views: 1353

Answers (1)

Tipu Sultan
Tipu Sultan

Reputation: 1865

in this case List.generate will return List<Todo>. It is a good practice to give the type of the list.

final todos = List<Todo>.generate(
  20,
  (i) => Todo(
    'Todo $i',
    'A description of what needs to be done for Todo $i',
  ),
);

If you want any object's type just simply use yourobject.runtimeType

Upvotes: 1

Related Questions