どうも、ちょげ(@chogetarou)です。
DrawerHeaderの背景画像を設定する方法を紹介します。
方法

DrawerHeaderの背景画像を設定するには、BoxDecorationを使います。
まず、DrawerHeaderの引数「decoration」に「BoxDecoration」を指定します。
次に、引数「image」にDecorationImageを指定します。
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(),
)
child: Container(),
),
そして、DecorationImageの引数「image」にAssetImageもしくはNetworkImageなどで画像を指定します。
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(), //NetworkImageでも可
),
),
child: Container(),
),
これでDrawerHeaderの背景画像を設定することが出来ます。
以下は、使用例です。
使用例
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(),
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://cdn.pixabay.com/photo/2016/10/31/14/55/rottweiler-1785760__340.jpg'),
),
),
child: Container(),
),
],
),
),
),
);
}

コメント