我正在尝试使用下面示例中 modelList 中的 name
查找 id
。
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);
}
答案 0 :(得分:1)
String foundString = modelList.firstWhere((abc) => abc.id == idToFind).name;