Flutter drawer background image
Asked Answered
S

2

7

I wonder if i can use background image instead of color in flutter app drawer header, Is there any way?

I am able to customize he color but i am wonder if is there any property to alter the color with custom image.

Shoreline answered 16/6, 2019 at 16:33 Comment(0)
B
22

You can use decoration in DrawerHeader to set image as drawer header

  return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(child: Text('some text')),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              child: Text('Drawer Header'),
              decoration: BoxDecoration(
                color: Colors.blue,
                image: DecorationImage(
                  image: AssetImage("assets/gold.jpg"),
                     fit: BoxFit.cover)
              ),
            ),
            ListTile(
              title: Text('Item 1'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );

also see this link

enter image description here

Blakeblakelee answered 16/6, 2019 at 16:52 Comment(0)
E
2

Declare a container inside it. this worked for me :

Drawer(
    elevation: 5,
    child: Container(
      width: 200,
      height: 100,
      decoration: BoxDecoration(
        image: new DecorationImage(
          image: AssetImage("lib/assets/bookcover.jpg"),
          fit: BoxFit.cover,
        ),
      ),
Exaltation answered 24/9, 2020 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.