gpt4 book ai didi

dart - 如何在 Dart 中对 MappedListIterable 进行排序

转载 作者:行者123 更新时间:2023-12-03 03:13:06 25 4
gpt4 key购买 nike

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

当调用排序方法时,我得到了

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

最佳答案

你在调用 .map(f) 后得到一个 MappedListIterableIterable 上。

Iterable class没有 sort() 方法。这个方法在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();

关于dart - 如何在 Dart 中对 MappedListIterable 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41303656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com