[Flutter]DrawerHeaderの背景にグラデーションを設定するには?

Flutter

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

DrawerHeaderの背景にグラデーションを設定する方法を紹介します。

スポンサーリンク

方法

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

DrawerHeaderの背景にグラデーションを設定するには、BoxDecorationを使います。

まず、DrawerHeaderの引数「decoration」にBoxDecorationを指定します。

そして、BoxDecorationの引数「gradient」にグラデーションを設定します。

グラデーションの設定には、LinearGradientやRadialGradientなどを使います。

DrawerHeader(
  decoration: BoxDecoration(
    gradient: /*グラデーション*/,
  ),
  child: Container(),
),

以下は、使用例です。

使用例
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(),
        drawer: Drawer(
          child: ListView(
            children: [
              DrawerHeader(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [
                      Colors.pink,
                      Colors.yellow,
                    ],
                  ),
                ),
                child: Container(),
              ),
            ],
          ),
        ),
      ),
    );
  }

コメント

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