10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Flutter】 Layoutチートシート (Column & Row Widget)

10
Last updated at Posted at 2020-05-06

概要

Flutterの「Column Widget」と「Row Widget」を使ったレイアウトを紹介します。

レイアウト一覧

[ 原型 ]

Collage_Fotor.jpg

main.dart
Column /*or Row*/(
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

VerticalDirection

VerticalDirection.up

スクリーンショット 2020-05-06 15.27.44.png

main.dart
Column(
  verticalDirection: VerticalDirection.up,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

VerticalDirection.down

スクリーンショット 2020-05-06 15.33.24.png

main.dart
Column(
  verticalDirection: VerticalDirection.down,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisAlignment

MainAxisAlignment.start

Collage_Fotor2.jpg

main.dart
Column /*or Row*/(
  mainAxisAlignment: MainAxisAlignment.start,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisAlignment.end

Collage_Fotor3.jpg

main.dart
Column /*or Row*/(
  mainAxisAlignment: MainAxisAlignment.end
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisAlignment.center

Collage_Fotor4.jpg

main.dart
Column /*or Row*/(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisAlignment.spaceAround

Collage_Fotor5.jpg

main.dart
Column /*or Row*/(
  mainAxisAlignment: MainAxisAlignment.spaceAround,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisAlignment.spaceEvenly

Collage_Fotor6.jpg

main.dart
Column /*or Row*/(
  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisAlignment.spaceBetween

Collage_Fotor7.jpg

main.dart
Column /*or Row*/(
  mainAxisAlignment: MainAxisAlignment.spaceBetween,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

CrossAxisAlignment

※CrossAxisAlignmentの効果をみるため、4つ目のContainerを追加しました。

CrossAxisAlignment.start

Collage_Fotor8.jpg

main.dart
Column /*or Row*/(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
    Container()
  ],
),

CrossAxisAlignment.end

Collage_Fotor9.jpg

main.dart
Column /*or Row*/(
  crossAxisAlignment: CrossAxisAlignment.end,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
    Container()
  ],
),

CrossAxisAlignment.center

Collage_Fotor10.jpg

main.dart
Column /*or Row*/(
  crossAxisAlignment: CrossAxisAlignment.center,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
    Container()
  ],
),

CrossAxisAlignment.stretch

Collage_Fotor11.jpg

main.dart
Column /*or Row*/(
  crossAxisAlignment: CrossAxisAlignment.stretch,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
    Container()
  ],
),

MainAxisSize

MainAxisSize.min

Collage_Fotor12.jpg

main.dart
Column /*or Row*/(
  mainAxisSize: MainAxisSize.min,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),

MainAxisSize.max

Collage_Fotor13.jpg

main.dart
Column /*or Row*/(
  mainAxisSize: MainAxisSize.max,
  children: <Widget>[
    Container(
      height: 100,
      width: 100,
      color: Colors.pink,
      child: Text('Container 1'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.cyan,
      child: Text('Container 2'),
    ),
    Container(
      height: 100,
      width: 100,
      color: Colors.green,
      child: Text('Container 3'),
    ),
  ],
),
10
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?