如何实现`where`来过滤颤振列表中的数据?

时间:2020-09-14 09:11:27

标签: flutter filter flutter-listview

我是初学者,我正在尝试在where上实现List来过滤数据,但我完全错了,请指导我正确的实现方式

实施

 List filterproducts=   productslist.where(widget.bomdatareceived[0]['purchase_items'][0]['product_code'].contains(widget.product_code));

错误

type 'bool' is not a subtype of type '(dynamic) => bool'

JSON数据

"purchase_items": [
               {
                     
                   "product_code": "61",
                   "name": "SPINNING",
                   "bom_catalog_item": "327",
                  },
                  {
                     
                   "product_code": "61",
                   "name": "SPINNING",
                   "bom_catalog_item": "390",
                   },
                   {
                     
                    "product_code": "65",
                    "name": "DYING",
                    "bom_catalog_item": "1056",
                   }
                   ]

4 个答案:

答案 0 :(得分:0)

List filterproducts=   productslist.where((i) => widget.bomdatareceived[0]['purchase_items'][0]['product_code'].contains(widget.product_code));

答案 1 :(得分:0)

List filterproducts= productslist.where((f) => f.bomdatareceived[0]['purchase_items'][0]['product_code'].contains(widget.product_code)).toList();

答案 2 :(得分:0)

var filterproducts=[];
filterproducts.addAll(widget.bomdatareceived[0]['purchase_items'][0]['product_code']
        .where((element) => element.contains(widget.product_code))
        .toList());

答案 3 :(得分:0)

enter image description here

结果:

enter image description here

代码:

  var purchase_items = [
               {
                     
                   "proc_code": "61",
                   "name": "SPINNING",
                   "bom_catalog_item": "327",
                  },
                  {
                     
                   "proc_code": "61",
                   "name": "SPINNING",
                   "bom_catalog_item": "390",
                   },
                   {
                     
                    "proc_code": "65",
                    "name": "DYING",
                    "bom_catalog_item": "1056",
                   }
                   ];
 List<Map<String,String>> filterproducts = new List<Map<String,String>>();


filterproducts = purchase_items.where((f) => f['proc_code'] == ('61')).toList();
  print(filterproducts);