[Flutter]RawMaterialButtonのサイズを設定するには?

Flutter

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

RawMaterialButtonのサイズを設定する方法を紹介します。

スポンサーリンク

方法

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

RawMaterialButtonのサイズを設定するには、引数「constraints」を使います。

まず、RawMaterialButtonの引数「constrains」にBoxConstraintsを指定します。

そして、BoxConstraintsの引数にサイズを指定します。

RawMaterialButton(
  constraints: BoxConstraints(
    minHeight: height, //最小の高さ
    minWidth: width, //最小の横幅
  ),
  onPressed: () {},
  child: Text('Button'),
),

BoxConstraintsで指定したサイズが、RawMaterialButtonのサイズに設定されます。

使用例

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: RawMaterialButton(
            constraints: BoxConstraints(
              minHeight: 50.0,
              minWidth: 100,
            ),
            fillColor: Colors.blue,
            textStyle: TextStyle(
              color: Colors.white,
            ),
            onPressed: () {},
            child: Text('Button'),
          ),
        ),
      ),
    );
  }

コメント

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