首页 > 解决方案 > 在列中放置一个小部件会在布局期间为 RenderIndexedStack 对象提供无限大小

问题描述

我将以下内容放在这样的列中

   Widget _getDropDownCombo()
    {
       Widget combo =  new DropdownButton(
            value: _currentItem,
               items:_dropDownMenuItems,
            onChanged: _changedDropDownItem
            );
       return Flexible(child:combo);
    }

并且 _getDropDownCombo在这样的地方被连续调用

child: new Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                        _getDropDownCombo(),
                        getIcon(),
                    ],)

这给了我错误颤振:══╡通过渲染库╞═══════════════════════════════════ ═══════════════════════

flutter: The following assertion was thrown during performLayout():
flutter: RenderIndexedStack object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
flutter: The nearest ancestor providing an unbounded width constraint is:
flutter:   RenderFlex#dfcbf relayoutBoundary=up17 NEEDS-LAYOUT NEEDS-PAINT

为什么 DropDownButton 会出现此错误?有什么建议么 ?

标签: dartflutter

解决方案


由于 DropdownButton 中的项目,它们可能是问题。我试过在项目中使用它,它工作得很好:

items: ['Foo', 'Bar'].map((String value) {
                    return new DropdownMenuItem(
                      value: value,
                      child: new Text(value),
                    );
                  }).toList(),

推荐阅读