简体   繁体   中英

How to perform a search in array of object flutter?

I am having a Map list with key and values, for example:

map<String, dynamic> my_List = [{"name": "mike", "age": "20"}, {"name":"william","age": "23"}].

I already tried containsValue but I don't want to use it.

The result i need to get is, when i search for mi need to get [{"name": "mike", "age": "20"}, {"name":"william","age": "23"}], and when i search 3 i need the result as [{"name":"william","age": "23"}].

You could create a Person or User class as julemand101 has suggested but if You have to work with Map try this:

List<Map<String, dynamic>> search(String input){
 return my_List.where((e) => e["name"].contains(input) || e["age"].contains(input)).toList();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM