【发布时间】:2019-11-19 12:30:40
【问题描述】:
我是 Dart 和 Flutter 的新手,我正在尝试使用这个模块 https://github.com/AbdulRahmanAlHamali/flutter_typeahead 来制作一个具有自动完成/“提前输入”功能的文本字段。
在他们给出的示例中,当用户选择其中一个建议时,他们会将用户路由到另一个视图,但我不想这样做。我只想将输入文本的值设置为用户选择的任何值。
这是我的代码:
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
autofocus: true,
style: DefaultTextStyle.of(context).style.copyWith(
fontStyle: FontStyle.italic
),
decoration: InputDecoration(
border: OutlineInputBorder()
)
),
suggestionsCallback: (pattern) async {
Completer<List<String>> completer = new Completer();
completer.complete(<String>["cobalt", "copper"]);
return completer.future;
},
itemBuilder: (context, suggestion){
return ListTile(
title: Text(suggestion)
);
},
onSuggestionSelected: (suggestion) {
}
)
],
),
)
);
}
}
我不知道在onSuggestionSelectedparameter 函数中放入什么来实现我所描述的。
【问题讨论】:
标签: flutter dart autocomplete flutter-typeahead