ListView / Column中的DropdownButton导致呈现错误

时间:2019-01-12 02:14:13

标签: dart flutter mobile-development

我试图让一个DropdownButton显示在ListView中。尽管ListView代码位于另一个文件中,但此按钮是该ListView的直接子代。

尝试直接添加小部件不起作用,出现此错误:

I/flutter (22767): RenderIndexedStack object was given an infinite size during layout.
I/flutter (22767): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (22767): inside another render object that allows its children to pick their own size.

因此,我尝试将其放在一个简单的Column / Flexible组合中,不添加任何其他内容,因为这是我从Google看到的建议。

widgets.add(Column(children: [Flexible(child: subdropdown)],));

这给了我这个错误:

I/flutter (22767): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (22767): When a column is in a parent that does not provide a finite height constraint, for example if it is
I/flutter (22767): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (22767): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (22767): space in the vertical direction.
I/flutter (22767): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (22767): cannot simultaneously expand to fit its parent.
I/flutter (22767): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter (22767): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter (22767): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter (22767): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter (22767): constraints provided by the parent.

然后,我尝试按照以下说明进行操作,并设置mainAxisSizeFlexFit只是恢复了原始错误。

widgets.add(Column(mainAxisSize: MainAxisSize.min, children: [Flexible(child: subdropdown, fit: FlexFit.loose)],));

我看过this线程,但是该线程具有下拉渲染某物,只是渲染不正确。我遇到的错误中断了渲染,因此它根本不显示任何内容。

0 个答案:

没有答案