Flutter Wrapの要素を左に寄せるサンプル
環境
Windows11 pro 64bit
Flutter 3.3.7
構文
SizedBox(
width: /*横幅*/,
child: Wrap(
children: <Widget>[ xxx
SizedBox(
width: /*横幅*/,
child: Wrap(
children: <Widget>[ xxx
SizedBox( width: /*横幅*/, child: Wrap( children: <Widget>[ xxx
Wrapの要素を左に寄せるには、SizedBoxを使います。
WrapをSizedBoxでラップします。
SizedBoxの引数「width」に横幅を指定します。
使用例
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SizedBox(
width: double.infinity,
child: Wrap(
children: <Widget>[
for (var i = 0; i < 2; i++)
Container(
color: i.isEven ? Colors.red : Colors.gray,
width: 80,
height: 80,
),
],
),
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SizedBox(
width: double.infinity,
child: Wrap(
children: <Widget>[
for (var i = 0; i < 2; i++)
Container(
color: i.isEven ? Colors.red : Colors.gray,
width: 80,
height: 80,
),
],
),
),
),
);
}
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: SizedBox( width: double.infinity, child: Wrap( children: <Widget>[ for (var i = 0; i < 2; i++) Container( color: i.isEven ? Colors.red : Colors.gray, width: 80, height: 80, ), ], ), ), ), ); }