Flutter 在单击某个位置之前,颤振typeahead不会显示建议
我在我的flatterweb项目中使用了flatter-typeahead包。 问题是,当用户在文本字段中键入程序包时,直到单击页面上的某个地方,程序包才显示任何建议,然后显示。 这是我的密码:Flutter 在单击某个位置之前,颤振typeahead不会显示建议,flutter,flutter-web,Flutter,Flutter Web,我在我的flatterweb项目中使用了flatter-typeahead包。 问题是,当用户在文本字段中键入程序包时,直到单击页面上的某个地方,程序包才显示任何建议,然后显示。 这是我的密码: Container( height: 45, width: 250, decoration: searchBoxDecoration, child: TypeAheadField(
Container(
height: 45,
width: 250,
decoration: searchBoxDecoration,
child: TypeAheadField(
noItemsFoundBuilder: (BuildContext context) {
return Container(
width: 250,
height: 60,
child: Center(
child: Text(
'loading..',
style: TextStyle(color: Colors.black54),
textAlign: TextAlign.center,
),
),
);
},
loadingBuilder: (BuildContext context) {
return Container(
width: 250,
height: 60,
child: Center(
child: Text(
'loading..',
style: TextStyle(fontSize: 12.5),
),
),
);
},
errorBuilder: (BuildContext context, Object error) =>
Container(width: 0, height: 0),
textFieldConfiguration: TextFieldConfiguration(
scrollPadding: EdgeInsets.all(10),
textDirection: TextDirection.rtl,
maxLines: 1,
style: TextStyle(fontSize: 12.5),
decoration: searchFieldDecoration,
controller: this._typeAheadController),
suggestionsCallback: (pattern) async {
return await getSuggestions(pattern);
},
itemBuilder: (context, suggestion) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 9.0),
child: Center(
child: Text(
suggestion['major'],
textDirection: TextDirection.rtl,
textAlign: TextAlign.center,
)),
);
},
onSuggestionSelected: (suggestion) {
this._typeAheadController.text = suggestion['major'];
setState(() {
majorSearchFieldValue = suggestion['major'];
majorId = suggestion['id'];
});
},
)),
我的建议是:
Future<List> getSuggestions(String query) async {
await Future.delayed(Duration(milliseconds: 300));
http.Response response = await http.get('${Config.url}/major/title/$query');
if (response.statusCode == 200) {
var jsonToData = jsonDecode(response.body);
setState(() {
List data = jsonToData["majors"];
for (int i = 0; i < data.length; i++) {
majorsId.add(data[i]["id"]);
majors.add(data[i]["title"]);
}
});
return List.generate(5, (index) {
return {'major': majors[index], 'id': majorsId[index]};
});
} else {
throw Exception('Something went wrong');
}
Future-getSuggestions(字符串查询)异步{
等待未来。延迟(持续时间(毫秒:300));
http.Response-Response=wait http.get('${Config.url}/major/title/$query');
如果(response.statusCode==200){
var jsonToData=jsonDecode(response.body);
设置状态(){
列表数据=jsonToData[“专业”];
对于(int i=0;i
}
这个问题不存在,但当我得到一个新的建设,它显示出来