Flutter DrawerHeaderの背景画像を設定するサンプル

環境
Windows11 pro 64bit
Flutter 3.3.7

概要
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(),
)
DrawerHeaderの引数「decoration」に「BoxDecoration」を指定します。
引数「image」にDecorationImageを指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(),
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'xxxx'),
),
),
child: Container(),
),
],
),
),
),
);
}
@override Widget build(BuildContext context) { return SafeArea( child: Scaffold( appBar: AppBar(), drawer: Drawer( child: ListView( children: [ DrawerHeader( decoration: BoxDecoration( image: DecorationImage( image: NetworkImage( 'xxxx'), ), ), child: Container(), ), ], ), ), ), ); }
@override
Widget build(BuildContext context) {
  return SafeArea(
    child: Scaffold(
      appBar: AppBar(),
      drawer: Drawer(
        child: ListView(
          children: [
            DrawerHeader(
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: NetworkImage(
                    'xxxx'),
                ),
              ),
              child: Container(),
            ),
          ],
        ),
      ),
    ),
  );
}

 

Flutter

Posted by arkgame