【发布时间】:2021-10-12 02:24:05
【问题描述】:
所以基本上这就是我想要实现的目标
以红色 X 为 根小部件,所有小部件都需要围绕它构建
这里的所有小部件都将被'渲染' 动态,这意味着我从某个地方获取它们的信息,所以为了实现这一点,我想到了两个选项:
- 使用 Stack 小部件或其他我还没有找到的神秘布局小部件
- 使用会导致问题的简单列和行: 这是我正在使用的代码
Widget panelWidget(Panel panel) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
//WIDGETS ON THE LEFT
...panel.attachedPanels
.where((element) => element.attachedToSide == 3)
.map(
(e) => Container(
height: getH(e.panelHeight),
width: getW(e.panelWidth),
decoration:
BoxDecoration(border: Border.all(color: Colors.black)),
),
)
.toList(),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//WIDGETS ON TOP
...panel.attachedPanels
.where((element) => element.attachedToSide == 2)
.map(
(e) => Container(
height: getH(e.panelHeight),
width: getW(e.panelWidth),
decoration:
BoxDecoration(border: Border.all(color: Colors.black)),
),
)
.toList(),
Center( //THIS IS THE ROOT WIDGET
child: Container(
height: getH(panel.panelHeight),
width: getW(panel.panelWidth),
decoration:
BoxDecoration(border: Border.all(color: Colors.black)),
),
),
//WIDGETS ON THE BOTTOM
...panel.attachedPanels
.where((element) => element.attachedToSide == 0)
.map(
(e) => Container(
height: getH(e.panelHeight),
width: getW(e.panelWidth),
decoration:
BoxDecoration(border: Border.all(color: Colors.black)),
),
)
.toList(),
],
),
//WIDGETS ON THE RITGHT
...panel.attachedPanels
.where((element) => element.attachedToSide == 1)
.map(
(e) => Container(
height: getH(e.panelHeight),
width: getW(e.panelWidth),
decoration:
BoxDecoration(border: Border.all(color: Colors.black)),
),
)
.toList(),
],
);
}
请注意逻辑,因为我现在专注于首先弄清楚这一点,您可以看到下面的根小部件已注释,并且从 4 个侧面围绕它有我需要渲染的小部件列表,在纸上看起来不错但这是输出,我正在使用 Flutter Web :
如您所见,左右小部件未与根小部件对齐,因为它们遵循 Row 的交叉轴对齐方式。 Flutter 将这 2 个小部件放在中心,但这些小部件的大小不同,因此整个小部件树的中心点稍微移动了一点,我尝试了不同的组合,但它们都不起作用,任何帮助都是非常受欢迎
【问题讨论】:
标签: flutter flutter-layout flutter-web