2.
// ConstrainedBox,添加约束
class ConstrainedBoxDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
// 不添加限制
Container(
width: 350,
height: 80,
child: Text('width>maxWidthxxxxxxxxxxxxxxxxxxxxxxx'),
color: Colors.green,
),
SizedBox(height: 50,),
// 添加一个指定大小的盒子,限定其最大最小宽高
ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 200.0,
minWidth: 100.0,
maxHeight: 60.0,
minHeight: 20.0,
),
child: Container(
width: 350,
height: 80,
child: Text('width>maxWidthxxxxxxxxxxxxxxxxxxxxxxxxxx'),
color: Colors.green,
),
)
],
),
);
}
}