首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不更新的颤振小部件父级

不更新的颤振小部件父级
EN

Stack Overflow用户
提问于 2021-04-22 23:58:22
回答 2查看 98关注 0票数 0

我试图用Reorderable包创建一个可重排序项的列表;我有一个可重新排序的包装,其中有可重排序的列。我用了两个不同的列表。

代码语言:javascript
复制
List<Widget> items = [];

List childrenItems = [];

列表是根据如下所示的数据创建的

代码语言:javascript
复制
 List taskList = [
   // First child Item
   {
     "name":"NOrbert kRoSs",
     "sub-children":[
       "child1","child2"
     ],
   },   
   // Second child Item
   {
     "name":"Genius",
     "sub-children":[
       "Relerx","Yiuja","No filter"
     ],
   },

 ];

用于填充列表的方法。

代码语言:javascript
复制
  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(),
          ),
        );
    }
}

可重排序的

他们

代码语言:javascript
复制
      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,
          ), 

问题当我运行应用程序时,我得到下面的错误

代码语言:javascript
复制
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%的肯定没有重复的键,并从错误信息,它的父母没有更新。如何修复这个

EN

回答 2

Stack Overflow用户

发布于 2021-04-26 21:39:42

因为某种原因我不明白

代码语言:javascript
复制
children = [];

而不是

代码语言:javascript
复制
children.clear();

解决了我的问题。

票数 0
EN

Stack Overflow用户

发布于 2021-04-23 02:31:04

尝试使用不同的ValueKey

key.dart中的描述指出,在具有相同父级的Element中,LocalKey(ValueKey extended LocalKey)必须是唯一的。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67222245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档