提前点击TypeAhead调用build()颤振

时间:2020-05-21 16:25:58

标签: flutter typeahead

我有一个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);
      },
    );
  }

0 个答案:

没有答案
相关问题