[运行此代码时出现错误:Multiple widgets used the same GlobalKey.
因此,我可以解决此问题。我如何将键动态传递给listview.Builder。有可能通过吗?这是我的代码的简化版本:
GlobalKey<AutoCompleteTextFieldState<String>> key0 = new GlobalKey();
@override
Widget build(BuildContext context) {
return M Scaffold(
appBar: appBar,
body: SingleChildScrollView(
child: Container(
child: ListView.builder(
itemCount: 3,
itemBuilder: (context, index) {
return SimpleAutoCompleteTextField(
key: key0,
suggestions: suggestions,
textChanged: (text) => print(text),
clearOnSubmit: false,
textSubmitted: (text) => print(text)
),
}
),
),
),
);
}
将索引作为您的值
key: ValueKey(index),