这个片段有问题吗?定位的元素未显示,但其他元素显示。deviceHeight 在其他地方定义为设备的高度。
第一个容器将其他两个容器放在其下方。第二个容器正确显示在顶部,但第三个容器(定位(应该在第二个容器下方没有出现。欢迎听到任何替代方案。
Align(
alignment: Alignment.bottomCenter,
child: Stack(children: <Widget>[
Container(
color: Color(bgDark),
height: deviceHeight / 100 * 40,
),
Container(color: Colors.red, height: deviceHeight / 18),
Positioned(
top: 50,
child: Container(
color: Colors.green, height: deviceHeight / 1))
]))
向Positioned
Container
添加width
使其可见。
Align(
alignment: Alignment.bottomCenter,
child: Stack(
children: <Widget>[
Container(
color: Colors.blue,
height: 300,
),
Container(
color: Colors.red,
height: 200,
),
Positioned(
top: 50,
child: Container(
color: Colors.green,
height: 100,
width:100,
),
),
],
),
);
我不确定问题的确切原因,但似乎Positioned
需要height
和width
维度。