Flutter,为列中的每个 child 指定一个包装器小部件

Flutter, specify a wrapper widget for each child in column

在我的 Flutter 应用程序中,我有一个动态创建的列 children:

Column (
    children: _getWidgetsList(),
);

我的目标是Flexible 小部件包装从_getWidgetsList() 返回的每个项目,以便所有项目可以均匀分布在屏幕上。

不幸的是,如果我在 _getWidgetsList() 中这样做,我会得到一个错误:

The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.

是否有可能以某种方式为列中的每个 child 指定一个包装器?

您可以尝试像这样映射 children :

Column (
    children: _getWidgetsList().map((e) => Flexible(child: e,)).toList(),
);