如何在 Dart 中对 MappedListIterable 进行排序

How to sort a MappedListIterable in Dart

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

调用排序方法时,我得到

EXCEPTION: NoSuchMethodError: Class 'MappedListIterable' has no instance method 'sort'. Receiver: Instance of 'MappedListIterable' Tried calling: sort(Closure: (dynamic, dynamic) => dynamic)

您在 Iterable 上调用 .map(f) 后得到 MappedListIterable

Iterable class does not have a sort() method. This method is on List.

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

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

或一行(代码-高尔夫):

var i = [1, 3, 2].map((i) => i + 1).toList()..sort();