Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Dart:按双精度对地图列表进行排序_Flutter_Dart - Fatal编程技术网

Flutter Dart:按双精度对地图列表进行排序

Flutter Dart:按双精度对地图列表进行排序,flutter,dart,Flutter,Dart,我有一个dart中的地图列表,我想对其进行排序 我使用的列表: List<myModel> myList; (我想对视图进行排序,从高到低) 但我得到了这个错误: error: A value of type 'SplayTreeMap' can't be assigned to a variable of type 'List<myModel>'. 这很有效 有可能这样排序吗?您不能将列表传递给SplayTreeMap.from(…) 见: SplayTreeMa

我有一个dart中的地图列表,我想对其进行排序

我使用的列表:

List<myModel> myList; 
(我想对视图进行排序,从高到低)

但我得到了这个错误:

error: A value of type 'SplayTreeMap' can't be assigned to a variable of type 'List<myModel>'.
这很有效


有可能这样排序吗?

您不能将
列表
传递给
SplayTreeMap.from(…)

见:

SplayTreeMap.from(映射其他,[int-compare(K键1 K键2),bool-isValidKey(动态电位键)])
您需要使用
映射
或使用
SplayTreeMap.fromIterable(…)
():

SplayTreeMap.fromIterable(Iterable Iterable,{K键(动态元素)、V值(动态元素)、int比较(K键1 K键2)、bool isValidKey(动态电位键)})
您可以通过以下方式实现:

final filteredList=
SplayTreeMap.fromIterable(
myList,
键:(m)=>m,
值:(m)=>m.views,
比较:(a,b)=>
int.parse(a.views)。比较(int.parse(b.views))
);
以上是一个例子,请根据您的需要进行调整

编辑2:
根据您的编辑,您可以执行以下操作:

final temp=List.from(myList);
临时排序((a,b)=>int.parse(a.views.compareTo(int.parse(b.views));
过滤器列表=温度;

非常感谢!在我的案例中如何实现它?@karledbedts我添加了一个示例。@karledbedts过滤器列表的类型是什么?是
List
?@karledbedts您不能将
SplayTreeMap
分配给
列表
filteredList
是一个
列表,您试图将
SplayTreeMap
分配给它,这两种类型彼此不兼容。@karledbedts欢迎您=)。很高兴我能帮忙!
error: A value of type 'SplayTreeMap' can't be assigned to a variable of type 'List<myModel>'.
    filteredList = myList
        .where((snapshot) => snapshot.views > 0)
        .toList();