どうも、ちょげ(@chogetarou)です。
Columnの高さを画面サイズの比率で指定する方法を紹介します。
方法

Columnの高さを画面サイズの比率で指定するには、MediaQuery.of(context).size.heightを使います。
まず、ColumnをSizedBoxもしくはContainerのchildに指定します。
そして、SizedBoxもしくはContainerの引数「height」に、MediaQuery.of(context).size.heightに比率を掛けた値を指定します。
SizedBox( //Containerでも可
height: MediaQuery.of(context).size.height * (比率),
child: Column(
children: [
・・・
],
),
),
これでColumnの高さを画面サイズとの比率で指定することが出来ます。
使用例
以下は、使用例です。

@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
child: Column(
children: [
Expanded(
child: Container(
color: Colors.blue,
),
),
],
),
),
),
);
}
コメント