如何使 Simple AutoComplete Field 基于包含而不是 startsWith 建议
How to make flutter SimpleAutoCompleteField suggest based on contains not startWith
我在我的 flutter 项目中使用了 SimpleAutoCompleteTextField
,但我面临的问题是,除非我开始输入单词的开头而不是从单词的中间开始,否则我的建议不是正确的建议。示例:
当我在寻找单词"Astalavista"时,如果我输入"asta",它会被提示,但如果我输入"lavis",则不会提示,我需要修复这个出来了。
这是我的代码:
child: SimpleAutoCompleteTextField(
key: endKey,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: S.of(context).end_location_hint),
controller: endLocationTextEditingController,
suggestions: suggestions,
textChanged: (text) => currentText = text,
clearOnSubmit: true,
textSubmitted: (text) async {
await movingCameraToLocation(
double.parse(
allStations[suggestions.indexOf(text)]
.stationLatitude),
double.parse(
allStations[suggestions.indexOf(text)]
.stationLongitude));
toLocationName = text;
setState(() {});
},
),
尝试添加过滤器参数,我不确定它是否可以与 SimpleAutoCompleteTextField
一起使用,但官方文档指出
"itemFilter" 参数可与 AutoCompleteTextField <String>()
、
一起使用
您的过滤器将是:
itemFilter: (suggestion, input) =>
suggestion.toLowerCase().contains(input.toLowerCase()),```
我在我的 flutter 项目中使用了 SimpleAutoCompleteTextField
,但我面临的问题是,除非我开始输入单词的开头而不是从单词的中间开始,否则我的建议不是正确的建议。示例:
当我在寻找单词"Astalavista"时,如果我输入"asta",它会被提示,但如果我输入"lavis",则不会提示,我需要修复这个出来了。
这是我的代码:
child: SimpleAutoCompleteTextField(
key: endKey,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: S.of(context).end_location_hint),
controller: endLocationTextEditingController,
suggestions: suggestions,
textChanged: (text) => currentText = text,
clearOnSubmit: true,
textSubmitted: (text) async {
await movingCameraToLocation(
double.parse(
allStations[suggestions.indexOf(text)]
.stationLatitude),
double.parse(
allStations[suggestions.indexOf(text)]
.stationLongitude));
toLocationName = text;
setState(() {});
},
),
尝试添加过滤器参数,我不确定它是否可以与 SimpleAutoCompleteTextField
一起使用,但官方文档指出
"itemFilter" 参数可与 AutoCompleteTextField <String>()
、
您的过滤器将是:
itemFilter: (suggestion, input) =>
suggestion.toLowerCase().contains(input.toLowerCase()),```