[Flutter]ElevatedButtonの高さを設定する方法

Flutter

どうも、ちょげ(@chogetarou)です。

ElevatedButtonの高さを設定する方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

ElevatedButtonの高さを設定する方法は3つあります。

ElevatedButton.styleFrom

1つ目は、ElevatedButton.styleFromを使う方法です。

ElevatedButton(
  onPressed: () {},
  child: Text('Button'),
  style: ElevatedButton.styleFrom(
    fixedSize: Size.fromHeight(70),//高さを設定
  ),
),

ElevatedButtonの引数「fixedSize」によって、高さを設定することが出来ます。

「fixedSize」ではなく、引数「minimumSize」でも高さを設定することが出来ます。

Container

2つ目は、Containerを使う方法です。

ElevatedButtonをContainerの「child」に指定します。

そして、Containerの引数「height」で、高さを設定します。

Container(
  height: 80,
  child: ElevatedButton(
    onPressed: () {},
    child: Text('Button'),
  ),
),

ConstrainedBox

3つ目は、ConstrainedBoxを使う方法です。

ConstrainedBoxの引数「child」に、ElevatedButtonを指定します。

そして、ConstrainedBoxの引数「constraints」で、高さの設定をします。

ConstrainedBox(
  constraints: BoxConstraints.tightFor(height: 80),
  child: ElevatedButton(
    onPressed: () {},
    child: Text('Button'),
  ),
),

BoxConstraints.tightForの引数「height」で、高さを指定することが出来ます。

まとめ

ElevatedButtonの高さは、次の3つの方法を使って、高さを設定することが出来ます。

  • ElevatedButton.styleFrom
  • Container
  • ConstrainedBox

コメント

タイトルとURLをコピーしました