Dart VM version: 1.24.3 (Wed Dec 13 23:26:59 2017) on "macos_x64"
the code:
final List<int> list = [1,3,4];
final List<int> res = list.where((i) => true);
fails runtime:
type 'WhereIterable<int>' is not a subtype of type 'List<int>'
method where
:
Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test);
interface Iterable
:
abstract class Iterable<E> {...}
expected behavior:
compile time error.
Yup, Iterable
does not implement List
.
You are looking for .where((i) => true).toList()
.
I'm not looking for toList
method. I'm looking for the API that doesn't fail runtime after it compiles
Then I recommend you 馃憤 this issue: https://github.com/dart-lang/sdk/issues/31410
Most helpful comment
Yup,
Iterable
does not implementList
.You are looking for
.where((i) => true).toList()
.