问题描述
我正在使用用于 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,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,请尝试更改您的 RecommendationCallback 以不显示结果,例如:
suggestionsCallback: (pattern){
if (pattern.length > 1) {
return DegreeSearchService(uni:currentUniversity).getSuggestions(pattern);
}
},