Flutter typeahead 显示所有建议 ontap 字段(不需要)

问题描述 投票:0回答:2

我正在使用 flutter 的 typeahead 包来显示具有建议功能的文本字段,但我遇到了不需要的行为。当用户第一次点击该字段时,我不想显示任何建议,但它显示所有建议的列表,例如下拉字段。我什至已经设置了

getImmediateSuggestion: false 
但它仍然这样做[![在此处输入图像描述][1]][1]

              alignment: Alignment.center,
              //padding: EdgeInsets.symmetric(vertical: 16),
              //height: (0.0725 * y),
              child: TypeAheadFormField(
                keepSuggestionsOnLoading: false,
                hideOnEmpty: true,
                hideOnLoading: true,
                //initialValue: '',
                enabled: false,
                hideOnError: true,
                textFieldConfiguration: TextFieldConfiguration(
                  //textAlign: TextAlign.left,
                  //autofocus: true,
                  
                  controller: _typeAheadController,
                  style: TextStyle(color: mainTextColor, fontSize:14, fontWeight: FontWeight.w400 ),
                  decoration: InputDecoration(
                      filled: true,
                      fillColor: cardColor,
                      labelStyle: TextStyle(fontSize: (0.04*x), color: mainTextColor, fontWeight: FontWeight.w400),
                      hintText: 'Type degree',
                      hintStyle: TextStyle(fontSize: (14), color: hintColor, fontWeight: FontWeight.w400),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10.0),
                        borderSide: BorderSide.none),
                      focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10.0),
                        borderSide: BorderSide(color: hintColor, width: 0.8)
                      )
                    ),
                ),
                //suggestionsBoxController: ,
                getImmediateSuggestions: false,
                suggestionsCallback: (pattern){
                  return DegreeSearchService(uni: currentUniversity).getSuggestions(pattern);
                }, 
                itemBuilder: (context, suggestion){
                  return ListTile(
                    dense: true,
                    title: Text(suggestion, style: TextStyle(fontSize: 14,color: Colors.black),)
                  );
                }, 
                onSuggestionSelected: (suggestion){
                  _typeAheadController.text = suggestion;
                  currentDegree = suggestion;//enable next press
                  //pageController.animateToPage(++currentPage, duration: Duration(milliseconds: 250), curve: Curves.bounceInOut );

                }
              )
            ), ```


  [1]: https://i.stack.imgur.com/FUXjl.png
flutter flutter-dependencies typeahead
2个回答
0
投票

尝试更改您的 suggestCallback,使其在模式长度为 0 时不显示结果,例如:

suggestionsCallback: (pattern){
  if (pattern.length > 1) {
    return DegreeSearchService(uni:currentUniversity).getSuggestions(pattern);
  }

}, 

0
投票

您可以使用属性“minCharsForSuggestions”并将其值设置为您想要的任何数字。

© www.soinside.com 2019 - 2024. All rights reserved.