Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter drawer background image

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.

like image 454
Aqib Farid Avatar asked Jun 16 '19 16:06

Aqib Farid


2 Answers

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

like image 121
Shojaeddin Avatar answered Oct 06 '22 21:10

Shojaeddin


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,
        ),
      ),
like image 32
user3614883 Avatar answered Oct 06 '22 22:10

user3614883