我想得到的地图有最大的视图值?
String api =
'http:///';
await Dio().get(api).then((value) {
// print(value);
if (value.toString() != 'null') {
for (var items in json.decode(value.data)) {
print(items);
Map<String, dynamic> greatestView = items.fold(
{},
(previous, current) => previous['view'] == null
? current
: previous['view']! >= current['view']!
? previous
: current);
print(greatestView);
异常发生。NoSuchMethodError (NoSuchMethodError: Class '_InternalLinkedHashMap<String,>'没有实例方法'fold')接收端:_LinkedHashMap len:2尝试调用:fold(_LinkedHashMap len:0, Closure: (dynamic, dynamic) =>动态)
你有一个地图列表,你想获得视图值最大的地图?我建议这样做:
Map<String, dynamic> greatestView = data.fold({},
(previous, current) => previous['view'] == null
? current
: previous['view']! >= current['view']!
? previous
: current
);
看起来view
是一个字符串,下面是这种情况下的代码:
Map<String, dynamic> greatestView = data.fold({},
(previous, current) => previous['view'] == null
? current
: int.parse(previous['view']!) >= int.parse(current['view']!)
? previous
: current
);