I have a class called Product
which has two properties.
class Product {
final String productName;
final int expiryTime;
Product(this.productName, this.expiryTime);
}
I then made a list of Product
s like below:
List<Product> allProducts = [
Product('Apple', 5),
Product('Banana', 3),
Product('Pear', 7),
];
I want to search this list to check if a product is in it. For example, if I check if 'Apple' is in the list allProducts
, it should be true
.
For other lists I have used list.contains()
but I cannot see how to use it for this type of list.
any returns true
if the given condition is met in dart list. Hope it helps
var found = allProducts.any((e) => e.productName == "Apple");
print(found);
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