第一种写法
1 ConstrainedBox( 2 constraints: BoxConstraints( 3 maxHeight: 100 4 ), 5 child: Stack( 6 overflow: Overflow.clip, 7 children: <Widget>[ 8 Container( 9 width: 100, 10 height: 200, 11 color: Colors.greenAccent, 12 ) 13 ], 14 ), 15 ),
第二种写法
Container( color: KColor.redBg, constraints: BoxConstraints(maxWidth: 500.w), child: Stack( overflow: Overflow.clip, children: [ Container( width: 600.w, color: KColor.blackTextColor, ), ], ), ),