FlutterでColumn
の要素を横幅いっぱいに表示する方法を紹介します。
Column
の基本的な使い方、知っておきたい基本プロパティのまとめ記事はこちら↓
あわせて読みたい


【Flutter】Columnの使い方|垂直に複数のウィジェットを並べる
Columnの基本的な使い方について解説します。Columnを使用することで複数のウィジェットを垂直に並べられます。また並んでいるウィジェットの配置を指定したり、逆順にしたりなどできます。
目次
Columnを横幅いっぱいに表示する方法
Columnの要素を横幅いっぱいに表示するにはSizedBox
を使用します。
使用方法としてはSizedBox
の子ウィジェットとしてColumn
を指定し、width
にdouble.infinity
を渡します。
SizedBox(
width: double.infinity,
child: Column(
children: [
...
],
),
)
Columnの要素を横幅いっぱいに表示する方法
Column
の要素を横幅いっぱいに表示したい場合は、次のように要素のwidth
を指定せずheight
のみ指定します。
SizedBox(
width: double.infinity,
child: Column(
children: [
Container(
height: 150,
color: Colors.red,
),
Container(
height: 150,
color: Colors.yellow,
),
Container(
height: 150,
color: Colors.blue,
),
],
),
)
サンプルコード
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Flutter')),
body: SizedBox(
width: double.infinity,
child: Column(
children: [
Container(
height: 150,
color: Colors.red,
),
Container(
height: 150,
color: Colors.yellow,
),
Container(
height: 150,
color: Colors.blue,
),
],
),
),
),
);
}
}
合わせて読みたい
あわせて読みたい


【Flutter】Sliderの使い方|スライダーを左右に移動させて数値を選択
FlutterのSliderウィジェットの用途と使い方のまとめ記事です。本記事ではSliderのサンプルコードを使いながら基本的な使い方、知っておきたい基本プロパティを解説して…
あわせて読みたい


【Flutter】CheckBoxの使い方|チェックボックスを実装
FlutterのCheckBoxウィジェットの用途と使い方のまとめ記事です。本記事ではCheckBoxのサンプルコードを使いながら基本的な使い方、知っておきたい基本プロパティを解説…
あわせて読みたい


【Flutter】CheckboxListTileの使い方|ラベル付きチェックボックスを実装
FlutterのCheckboxListTileウィジェットの用途と使い方のまとめ記事です。本記事ではCheckboxListTileのサンプルコードを使いながら基本的な使い方、知っておきたい基本…
あわせて読みたい


【Flutter】Radioの使い方|ラジオボタン(オプションボタン)を実装
FlutterのRadioウィジェットの用途と使い方のまとめ記事です。本記事ではRadioのサンプルコードを使いながら基本的な使い方、知っておきたい基本プロパティを解説してい…