How to search a list of Object by another list of items in dart

后端 未结 5 1353
一向
一向 2021-02-14 08:00

How to search a list of a class object with one of its property matching to any value in another list of strings

I am able to get filtering based on a single string , bu

5条回答
  •  悲&欢浪女
    2021-02-14 08:18

    In case if you want to check for a value in a list of objects . you can follow this :

     List rows = [
              {"ags": "01224", "name": "Test-1"},
              {"ags": "01224", "name": "Test-1"},
              {"ags": "22222", "name": "Test-2"},
            ];
        
        bool isDataExist(String value) {
        var data= rows.where((row) => (row["name"].contains(value)));
          if(data.length >=1)
         {
            return true;
         }
        else 
         {
            return false;
         }
        }   
    

    you can put your own array of objects on rows . replace your key with name . you can do your work based on true or false which is returned from the function isDataExist

提交回复
热议问题