I am trying to check condition
if (value in List) { exist } else { not exist }
but nothing to help anyone having an idea then please share.
My List = _quantityController[];
itemId is integer
i want to check my item id exists in my list array or not...Thanks!
Using List.contains( ) is the recommended method to check if a value is present in a list or not. This method takes the value to be searched as a parameter and returns true if the item found otherwise returns false.
The contains() method is used to check if an element occurs in a list.
Check if Dart List contains Element using List.contains(element) returns true if the element is present in this list. Else, it returns false.
list.contains(x);
Contains method
Above are the correct answers to the current question. But if someone like me is here to check value inside List of Class object then here is the answer.
class DownloadedFile { String Url; String location; }
List of DownloadedFile
List<DownloadedFile> listOfDownloadedFile = List(); listOfDownloadedFile.add(...);
Now check if a specific value is inside this list
var contain = listOfDownloadedFile.where((element) => element.Url == "your URL link"); if (contain.isEmpty) //value not exists else //value exists
There maybe better way/approach. If someone know, then let me know. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With