【发布时间】:2020-11-07 14:08:02
【问题描述】:
Center 小部件将小部件水平和垂直居中在堆栈的中心。如何才能使小部件仅水平或垂直居中?
使用 Row 或 Column 小部件可以使小部件在 Stack 中居中。不使用这些小部件可以做到吗?
条件:
- 不能使用行/列。
- Stack 的大小在布局之前是未知的(不能使用硬编码的定位值)。
中心小部件:
Container(
decoration:
BoxDecoration(border: Border.all(color: Colors.black87, width: 10)),
child: Stack(
children: [
Center(
child: Container(color: Colors.amber, width: 50, height: 50),
),
],
),
);
水平居中 w/Row:
Row(mainAxisAlignment: MainAxisAlignment.center)
垂直居中/列:
Column(mainAxisAlignment: MainAxisAlignment.center)
上面的对齐是想要的结果。其他 Flutter 小部件可以实现这些结果吗?
【问题讨论】:
标签: flutter flutter-layout flutter-widget