Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Flutter Drawer Background Color

How can I change the background color of a flutter nav drawer? There doesn't seem to be a color or background-color property.

like image 956
AlexL Avatar asked Dec 23 '17 10:12

AlexL


People also ask

How do I change the drawer color in material UI?

To set the background color of the Material UI drawer, we call the makeStyles function to create the styles. Then we can apply the styles with the useStyles hook returned by makeStyles . We call makeStyles with an object that has the properties set to objects with the styles.

How do you change the background color column in Flutter?

How to change background color of column in Flutter DataTable (SfDataGrid)? The Syncfusion Flutter DataTable widget retrieves the widget from user end itself for each cell. So, users simply wrap the Text widget inside the Container and set the color for that container.


4 Answers

When you build your ListView in the child property of your Drawer, you can wrap your different sections of the Drawer inside a Container and use the color property of the Container.

enter image description here

drawer: new Drawer(
        child: new ListView(
          children: <Widget>[
            new Container(child: new DrawerHeader(child: new CircleAvatar()),color: Colors.tealAccent,),
            new Container (
              color: Colors.blueAccent,
              child: new Column(
                children: new List.generate(4, (int index){
                  return new ListTile(
                    leading: new Icon(Icons.info),
                  );
                }),
              ),
            )
          ],
        ),
      ),

A better alternative if you already have a consistent coloring design in your mind, is to define your ThemeData under the theme property of the root of your app, the DrawerHeader and the body will follow your canvasColor, so you need to override the value of one of them to change the color:

enter image description here

return new MaterialApp(
....
theme: new ThemeData(
       canvasColor: Colors.redAccent,

       ....),
)
like image 139
Shady Aziza Avatar answered Oct 12 '22 10:10

Shady Aziza


Best way to wrap Drawer with Theme,

For example:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        //other scaffold items
        drawer: Theme(
           data: Theme.of(context).copyWith(
                 canvasColor: Colors.blue, //This will change the drawer background to blue.
                 //other styles
              ),
              child: Drawer(
                 child: Column(
                    children: <Widget>[
                       //drawer stuffs
                    ],
                 ),
             ),
        );
  }
like image 21
Raj Yadav Avatar answered Oct 12 '22 11:10

Raj Yadav


The easiest way would probably be to just wrap the ListView inside a Container and specify its color like following:

drawer: Drawer(
  child: Container(color: Colors.red,
    child: new ListView(
      ...
    )
  )
)
like image 26
JonasH Avatar answered Oct 12 '22 11:10

JonasH


For changing Drawer Header color use blow code


UserAccountsDrawerHeader(
  accountName: Text("Ashish Rawat"),
  accountEmail: Text("[email protected]"),
  decoration: BoxDecoration(
    color: const Color(0xFF00897b),
  ),
  currentAccountPicture: CircleAvatar(
    backgroundColor: Theme.of(ctxt).platform == TargetPlatform.iOS
        ? const Color(0xFF00897b)
        : Colors.white,
    child: Text(
      "A",
      style: TextStyle(fontSize: 40.0),
    ),
  ),
),
like image 10
Shan Mk Avatar answered Oct 12 '22 11:10

Shan Mk