Reputation: 245
I have a list:
List user = [
{"name": "Alex", "id": "001"},
{"name": "Brandon", "id": "002"},
{"name": "Charlie", "id": "003"},
{"name": "Danny", "id": "004"},
];
and I have a variable with value
String a = "002";
int index;
My question is how to get an index value from a list of user
while I do a search by passing a value from a
?
So I'll have an index = 1
Thank you :)
Upvotes: 5
Views: 17647
Reputation: 814
If you have to search in respect to any value in Map then you can do the following.
int index = user.indexWhere((item) => item.containsValue(a));
Upvotes: 2
Reputation: 3768
int index = user.indexWhere((item) => item["id"] == a);
Upvotes: 14