i’m try to make Search Bar and Searching from Map<String, List>
but i got error like this –> "A value of type ‘Iterable<MapEntry<String, List>>’
can’t be assigned to a variable of type ‘Map<String, List>"
//here the function that i try.
Map<String, List> datasource_map = {};
Map<String, List> result = {};
void updateList(String enteredKeyword) {
setState(() {
result = datasource_map.entries.map((e) {
return MapEntry(
e.key,
e.value
.where(
(element) => element.foodName!.toLowerCase().contains(
enteredKeyword.toLowerCase(),
),
)
.toList());
});
print("### $result");
});
}
what should i try ? i am new at flutter
2
Answers
Thank you everyone! I solved it.
This works:
Looks like your datasource_map.entries is a List – calling a map() on it will produce an Iterator – not a Map object.
You should use Map.fromEntries constructor: