Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A value of type 'List<int>' can't be assigned to a variable of type 'Iterable<int>'

Tags:

flutter

dart

I don't know if this was happening before my switch to the beta channel in Flutter but I don't understand why this is an error. A List is an Iterable right? I took the example from the official docs.

Iterable<int> example() {
  Iterable<int> iterable = [1, 2, 3];
  return iterable;
}

VSCode marks the list with a red underline telling me:

A value of type 'List<int>' can't be assigned to a variable of type 'Iterable<int>'.
Try changing the type of the variable, or casting the right-hand type to 'Iterable<int>'. dart(invalid_assignment)
like image 414
Noxware Avatar asked Sep 13 '25 13:09

Noxware


1 Answers

You need convert again the results to List adding .toList() in the end because Dart changes the type of the variable.

like image 149
gparker Avatar answered Sep 16 '25 09:09

gparker