Flutter Cardに最小の横幅を設定するサンプル
環境
Windows11 pro 64bit
Flutter 3.3.7
構文
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: /*最小の横幅*/,
),
Cardに最小の横幅を設定するには、BoxConstraintsを使います。
使用例
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 180, //最小の横幅
),
child: Card(
child: Container(
height: 20,
width: 1,
child: Text('Study flutter'),
color: Colors.red,
),
),
),
),
);
}
説明
CardをBoxContrainstsのchildに指定します。
BoxConstraintsの引数「constraints」にBoxConstraintsを指定します。
BoxConstraintsの引数「minWidth」に最小の横幅を設定します。