Reputation: 3108
I'm trying to find the name
using the id
in modelList from the example below.
class Example{
List<Abc> modelList = [
Abc(1, "John"),
Abc(2, "Christine"),
Abc(3, "Steven"),
Abc(4, "Others"),
];
myFun(){
int idToFind = 4;
String foundString = // Some iterable function??
}
}
class Abc{
int id;
String name;
Abc(this.id, this.name);
}
Upvotes: 0
Views: 131
Reputation: 2303
String foundString = modelList.firstWhere((abc) => abc.id == idToFind).name;
Upvotes: 1