如何在 Dart 中对 MappedListIterable 进行排序

bwn*_*sse 1 dart dart-html

我有一个MappedListIterable比我知道的要排序的

调用排序方法时,我得到

例外:NoSuchMethodError:类“MappedListIterable”没有实例方法“sort”。接收器:'MappedListIterable' 的实例尝试调用:sort(Closure: (dynamic, dynamic) => dynamic)

Ale*_*uin 5

MappedListIterable.map(f)上调用.map(f)后你会得到一个Iterable

可迭代类没有一个sort()方法。此方法在List 上

因此,您首先需要通过调用List从您那里获取 a 。MappedListIterable.toList()

var i = [1, 3, 2].map((i) => i + 1);
// i is a MappedListIterable
// you can not call i.sort(...)

var l = i.toList();
l.sort(); // works
Run Code Online (Sandbox Code Playgroud)

或者在一行中(代码高尔夫):

var i = [1, 3, 2].map((i) => i + 1).toList()..sort();
Run Code Online (Sandbox Code Playgroud)