【发布时间】:2021-04-22 23:58:22
【问题描述】:
我正在尝试使用 Reorderables 包创建可重新订购的项目列表;我有一个可重新排序的包装,里面有可重新排序的列。我为此使用了两个不同的列表。
List<Widget> items = [];
List childrenItems = [];
列表是根据如下所示的数据创建的
List taskList = [
// First child Item
{
"name":"NOrbert kRoSs",
"sub-children":[
"child1","child2"
],
},
// Second child Item
{
"name":"Genius",
"sub-children":[
"Relerx","Yiuja","No filter"
],
},
];
用于填充列表的方法
generateList(List incoming){
List<Widget> children = [];
children.clear();
if(childrenItems.length > 0) {childrenItems.clear();}
if(items != null) items.clear();
if( incoming != null )
for(int n=0; n<=incoming.length-1;n++){
children.clear();
for(int sub = 0; sub<=incoming[n]["sub-children"].length-1;sub++){
children.add(
cardWidget(
header: incoming[n]["sub-children"][sub]["name"].toString(),
key: sub.toString(),
parentKey: incoming != null?n.toString():"0",
),
);
}
childrenItems.insert(n, children);
items.add(
mainListItem(
nPos: n,
header:incoming !=null?incoming[n]["name"].toString():"Aberor",
mainKeys: n.toString(),
),
);
}
}
可重新订购的物品
他们
ReorderableWrap(
children: items != null?
items:
(<Widget>[
Container(
key: ValueKey("newVal"),),
]),
onReorder: setRedorder),
ReorderableColumn(
children: childrenItems[nPos] != null?
childrenItems[nPos]:
(<Widget>[
Container(
height: 30,
color: Colors.redAccent,
width: 60.0,
key: ValueKey("value"),
),
]),
onReorder: setNewOrder,
),
问题 当我运行应用程序时,我收到以下错误
Duplicate GlobalKeys detected in widget tree.
The following GlobalKeys were specified multiple times in the widget tree. This will lead to parts of the widget tree being truncated unexpectedly, because the second time a key is seen, the previous instance is moved to the new location. The keys were:
[GlobalObjectKey ValueKey<String>#c9f0c]
[GlobalObjectKey ValueKey<String>#7990e]
[GlobalObjectKey ValueKey<String>#89542]
This was determined by noticing that after widgets with the above global keys were moved out of their respective previous parents, those previous parents never updated during this frame, meaning that they either did not update at all or updated before the widgets were moved, in either case implying that they still think that they should have a child with those global keys.
The specific parents that did not update after having one or more children forcibly removed due to GlobalKey reparenting are:
Column(direction: vertical, mainAxisAlignment: start, mainAxisSize: min, crossAxisAlignment: center, renderObject: RenderFlex#1c68d relayoutBoundary=up36)
我 100% 确定没有重复的键,并且从错误消息中可以看出它的父母没有更新。我该如何解决这个问题
【问题讨论】:
标签: flutter dart flutter-dependencies