Я пытаюсь создать поле поиска, которое выполняет поиск между объектами (по их «имени»).
List<SearchRecipeEntity> recipeEntitySuggest = [];
List<SearchRecipeEntity> recipemap= new List<SearchRecipeEntity>();
@override
void initState() {
...
for (var recipe in data['records']) {
recipeEntitySuggest.add(
SearchRecipeEntity(id: recipe['id'], name: recipe['name']));
}
recipemap= recipeEntitySuggest
.map<SearchRecipeEntity>((entry) =>
SearchRecipeEntity(id: entry.id, name: entry.name))
.toList();
setState(() {});
...
}
Widget _buildIngredientsAutocompleteTextField() {
return AutoCompleteTextField<SearchRecipeEntity>(
itemBuilder: (context, item) {
return row(item);
},
itemFilter: (item, query) {
return item.name.startsWith(query);
},
itemSorter: (a, b) {
return a.name.compareTo(b.name);
},
focusNode: myFocusNode,
key: searchRecipeKey,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: "חיפוש מתכון",
icon: Icon(
Icons.search,
color: Colors.white,
),
hintStyle: TextStyle(color: Colors.white)),
suggestions: recipemap,
clearOnSubmit: false,
submitOnSuggestionTap: true,
itemSubmitted: (item) => setState(() {
print("clicked on " + item.name + " id number " + item.name);
var route = new MaterialPageRoute(
builder: (BuildContext context) => new RecipePage(
title: item.name,
id: item.id,
));
Navigator.of(context).push(route);
}),
);
}
это ошибка, когда что-то вводится в поле поиска
The method 'map' was called on null.
Receiver: null
Tried calling: map<Row>(Closure: (SearchRecipeEntity) => Row)
Я не до конца понимаю, что проблема с картой, возможно, связана с «картой рецептов» или, возможно, с виджетом строк? Есть предложения?