[Flutter]ボタンの背景に画像を設定する方法

Flutter

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

ボタンの背景に画像を設定する方法を紹介します。

スポンサーリンク

方法

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

ボタンの背景に画像を設定するには、MaterialButtonとContainerを使います。

MaterialButton(
    padding: EdgeInsets.all(8.0),
    textColor: Colors.black,
    elevation: 8.0,
    child: Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage('asset/images/dog-illust.jpg'),
          fit: BoxFit.cover,
        ),
      ),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text("Button"),
      ),
    ),
    onPressed: () {},
  ),

MaterialButtonのchildにContainerを指定します。

そして、Containerのdecorationで、画像の設定をします。

これでボタンの背景に画像を設定することが出来ます。

まとめ

ボタンの背景に画像を設定するには、MaterialButtonとContainerを使います。

Containerの引数「decoration」で、画像の指定をします。

コメント

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