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

后端 未结 5 1351
一向
一向 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:19

     var one = [
        {'id': 1, 'name': 'jay'},
        {'id': 2, 'name': 'jay11'},
        {'id': 13, 'name': 'jay222'}
      ];
    
      int newValue = 13;
    
      print(one
          .where((oldValue) => newValue.toString() == (oldValue['id'].toString())));
    

    OUTPUT : ({id: 13, name: jay222})

    store output in any variable check if variable.isEmpty then new value is unique either

    var checkValue = one
          .where((oldValue) => newValue.toString() == (oldValue['id'].toString()))
          .isEmpty;
      if (checkValue) {
        print('Unique');
      } else {
        print('Not Unique');
      }
    

    OUTPUT : Not Unique

提交回复
热议问题