我有一个TypeAhead
小部件,每次单击以插入字符串时,都会再次调用build()
。
删除所有字符串并重写它不会进行重建,只是在小部件上的每一次轻按。
有什么方法可以防止重建吗?
Widget _buildIngredientsAutocompleteTextField() {
return TypeAheadField(
hideOnEmpty: true,
hideOnError: true,
keepSuggestionsOnLoading: false,
textFieldConfiguration: TextFieldConfiguration(
focusNode: myFocusNode,
autofocus: true,
style: TextStyle(fontSize: 18, color: Colors.white),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: "HINT",
hintStyle: TextStyle(color: Colors.white),
),
),
suggestionsCallback: (pattern) {
return getSuggestions(pattern);
},
itemBuilder: (context, suggestion) {
return ListTile(
trailing: FadeInImage.memoryNetwork(
fit: BoxFit.cover,
placeholder: kTransparentImage,
height: MediaQuery.of(context).size.width / 5,
width: MediaQuery.of(context).size.width / 5,
image:
"https://chefeat.net/recipes_pictures/" + suggestion.image),
title: AutoSizeText(suggestion.name,
maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: AutoSizeText(suggestion.writer,
maxLines: 1, overflow: TextOverflow.ellipsis),
);
},
loadingBuilder: (BuildContext context) {
return Center(child: CircularProgressIndicator());
},
onSuggestionSelected: (suggestion) {
print("clicked on " + suggestion.name + " id number " + suggestion.id);
var route = new MaterialPageRoute(
fullscreenDialog: true,
builder: (BuildContext context) => new Page(
title: suggestion.name,
id: suggestion.id,
));
Navigator.of(context).push(route);
},
);
}