当我运行此代码时,我收到错误: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),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)