在Stack中如果全部子元素都是Positioned元素, 那Stack必须有一个设置大小的父元素,否则会报错RenderStack object was given an infinite size during layout.
在Stack中将需要高度自适应的子元素设置成非Positioned元素, 通过padding来调整该元素的位置,实例如下
Stack(
children: <Widget>[
Positioned(
top: setSize(18),
right: setSize(6),
child: Transform.rotate(
angle: 3.14/4,
child: Container(
width: setSize(32),
height: setSize(32),
decoration: BoxDecoration(
color: Color(0xff0CC6B6),
borderRadius: BorderRadius.circular(setSize(4)),
),
),
)
),
Container(
padding: EdgeInsets.only(right: setSize(16)),
child: Container(
padding: EdgeInsets.symmetric(horizontal: setSize(24), vertical: setSize(14)),
constraints: BoxConstraints(
maxWidth: setSize(470)
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(setSize(10)),
color: Color(0xff0CC6B6)
),
child: Text('撒大发撒大发阿斯顿发送到发送到发送地方', style: TextStyle(color: Color(0xffffffff), fontSize: setFont(28), fontWeight: FontWeight.w400, height: 40/28)),
),
)
],
),