首页 > 解决方案 > 将 where 方法与 List 一起使用 Dart

问题描述

我在颤动中遇到问题我想做一个搜索栏并且我对 api 有响应并且我想显示来自服务器的数据,其中包含来自搜索栏的文本我的问题是方法不适用于列出任何想法?

标签: listapidictionarydartflutter

解决方案


查看您的评论,没有where关于String类型的方法。而不是for循环,你想要一些类似的东西:

// Remove the for loop
// for(var i = 0; i <map.length; i++) { _results = jsonDecode(map[i]['address']).where((p)=>p.startsWith(query)).toList(); }

// Do this instead
_results = map.where((item) => item['address'].startsWith(query)).toList();

您现在应该可以放弃 for 循环了。


推荐阅读