gpt4 book ai didi

flutter - 此小部件的所有子项都必须在 Reorderable Listview 中有一个键

转载 作者:行者123 更新时间:2023-12-02 03:10:16 27 4
gpt4 key购买 nike

我想重新排序我的列表,但出现此错误。 此小部件的所有子项都必须在 Reorderable Listview 中有一个键

Widget list(list) {
return Scrollbar(
child: ReorderableListView(
header: null,
onReorder: _onReorder,
padding: const EdgeInsets.symmetric(vertical: 8.0),
children: <Widget>[
ListView.builder(
itemCount: list.length,
shrinkWrap: true,
itemBuilder: (contex, index) {
return _singleToDoWidget(list[index], index);
},
)
]),
);
}

最佳答案

用于唯一标识列表中的每个项目,因为您将移动它们。
你可以这样做:

ReoderableListView(
header: null,
onReorder: _onReorder,
children: [
for(var i; i < list.length; i++) {
Container(
key: ValueKey(list[index]),
child: _singleToDoWidget(list[index], index),
}
],
);

或者您可以在小部件函数本身中指定

Widget _singleToDoWidget(String title, int index) {
return YourRootWidget(
key: ValueKey(title),
...
),
}

只是试图说明您的实现以及 key 将去向

关于flutter - 此小部件的所有子项都必须在 Reorderable Listview 中有一个键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57805166/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com