どうも、ちょげ(@chogetarou)です。
DrawerHeaderの背景にグラデーションを設定する方法を紹介します。
方法

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(),
),
],
),
),
),
);
}

コメント