Flutter typeahead显示所有建议ontap字段(UNWANTED)



我正在使用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

如果模式长度为0,请尝试更改您的suggestionsCallback以不显示结果,例如:

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

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

最新更新