flutter - 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)
]
),
),
],
),
),
),
],
),
),
);
}
解决方案
问题是你column
的column
.
并且由于列具有无限的高度。它会引发溢出错误。
你可以做的column
是container
用Expanded
.
推荐阅读
- python - 将值与 pandas DataFrame 中的前一行进行比较并用黄色和绿色着色
- firebase - Imagepicker'XFile'不是类型转换和Firebase存储图像上传错误中'File'类型的子类型
- python - 熊猫如何将函数应用于 groupby().first()
- zpl - ZEBRA ZPL 标签格式与文本一起打印报价单
- tensorflow - 在 tensorflow 2.3 中执行量化感知训练 (QAT) 时无法访问正则化损失值
- sql - 将多行转换为列
- r - 拆分矩阵列,无需中间转换为矩阵
- python - 将 tkinter 条目链接到彼此的输入
- heroku - 是否可以在 Heroku 上运行不和谐音乐机器人?
- ansible - 使用 Ansible 安装 Elastic Search 插件