首页 > 解决方案 > Flutter:EXPANDED 的错误虽然已经用 COLUMN 包装了

问题描述

我只是想根据列表创建一些文本标签并将它们输出到可扩展列的单元格中。好的,今天我了解到我需要将 EXPANDED 放在前面,另外 EXPANDED 需要用 FLEX、ROW 或 COLUMN 包装。

但我不断收到一个错误

 The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a
RenderObject, which has been set up to accept ParentData of incompatible type BoxParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically,
Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside an Align widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
  _ScrollSemantics-[GlobalKey#05460] ← Scrollable ← PrimaryScrollController ← SingleChildScrollView
← Expanded ← Align ← Padding ← DecoratedBox ← Padding ← Container ← ⋯
child: Column(
  children: <Widget>[
    CupertinoButton(
      child: Text('expand', style: TextStyle(color: CupertinoColors.activeBlue)),
      onPressed: () {
        setState(() {
          step1Expanded = !step1Expanded;
        );
      },
    ), //Button
    Container(
      child: Column(
        children: <Widget>[
          Expanded(
            flex: 1,
            child: (step1Expanded)? step1RowWidget(taskPrmtrs) : Container()
          ),
        ] //Widget
      ),
    ), //Container
  ],
),

Widget step1RowWidget(List<Parameter> parameters)  {
  TextEditingController name;
   Row(
      children: <Widget>[
        Text("Hallo"),
        Column(
          children: <Widget>[
              for (var parameter in parameters) Text(parameter.descr)
            ],
          ),
        Column(
          children: <Widget>[
            for (var parameter in parameters) Text(parameter.descr)
//            for (var parameter in parameters) _createTextField()
          ],
        ),
  ],
  );
}

Widget _createTextField() {
  TextEditingController name;
  CupertinoTextField(
    controller: name,
    decoration: BoxDecoration(
      ),
    placeholder: "Wert",
    );
}

该错误发生在扩展行中的片段中间略上方。还有什么问题?

更新:通过添加 2 EXPANDED 行,我解决了这个问题(基于下面的答案)。我还需要上面的 EXPANDED(CONTAINER( 来修复它。但是,当屏幕打开时,最外面的 COLUMN 的第二个外部 CONTAINER 现在将屏幕填充到底部(包裹按钮列和内部动态列的那个) . 预期行为:CUPERTINOBUTTON 的父 CONTAINER 应紧紧包裹在 BUTTON 周围(基于边距/填充),并且不应在屏幕底部创建空白空间。这似乎是由 EXPANDED 引起的,我猜

  navigationBar: CupertinoNavigationBar(
      middle: Text('Header'),
    ),
    child: SafeArea(
      child: Column(
        children: <Widget>[
          Container(
            alignment: Alignment.center,
            margin: new EdgeInsets.all(10.0),
            padding: new EdgeInsets.all(10.0),
            child: new Expanded(
              flex: 1,
              child: new SingleChildScrollView(
                scrollDirection: Axis.vertical,//.horizontal
                child: Text(fillParamGeneric(taskText, taskPrmtrs)),
              ),
            ),
          ),
          Expanded ( // ADDED according to answers here
            child: Container( // ADDED "child:"
              alignment: Alignment.center,
              margin: new EdgeInsets.all(10.0),
              padding: new EdgeInsets.all(10.0),
              child: Column(
                children: <Widget>[
                  CupertinoButton(
                    child: Text('expand', style: TextStyle(color: CupertinoColors.activeBlue)),
                    onPressed: () {
                      setState(() {
                        step1Expanded = !step1Expanded;
                      });
                    },
                  ),
                  Expanded( // ADDED according to answers here
                    child: Column(
                        children: <Widget>[
                          (step1Expanded)? step1RowWidget(taskPrmtrs) : Container(width: 0.0, height: 0.0)
                        ]
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    ),
  );
}

标签: flutterdartwidget

解决方案


问题是你columncolumn.

并且由于列具有无限的高度。它会引发溢出错误。

你可以做的columncontainerExpanded.


推荐阅读