Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to change UserAccountsDrawerHeader background

Tags:

flutter

dart

I'm trying to change the UserAccountsDrawerHeader background from light blue to another color in my Drawer but I'm not able to find a solution. Can anyone help me?

return Drawer(
  child: ListView(
    // Important: Remove any padding from the ListView.
    padding: EdgeInsets.zero,
    children: <Widget>[
      UserAccountsDrawerHeader(
        accountName: Text(sessionUsername),
        accountEmail: Text(mail),
        currentAccountPicture: CircleAvatar(
          backgroundColor: Colors.red,
          backgroundImage: NetworkImage(gravatarUrl),
        ),
      ),
      ListTile(
        title: Text('Home'),
        leading: Icon(Icons.home, color: myColor),
        onTap: () {
          print("Going to home");
          //Close the drawer
          Navigator.of(context).pop();
          //Navigate to home page
          //Navigate with avoiding the possibility to return
          Navigator.of(context).pushReplacementNamed(HomePage.tag);
        },
      ),

    ],
  ),
);

MyDrawer:

MyDrawer

like image 405
E.Benedos Avatar asked Mar 29 '19 15:03

E.Benedos


1 Answers

Since you've not specified the decoration property, color is set to default primaryColor of theme. Use decoration property to set color.

UserAccountsDrawerHeader(
    decoration: BoxDecoration(
        color: Colors.red,
    ),
    accountName: Text(sessionUsername),
    accountEmail: Text(mail),
    currentAccountPicture: CircleAvatar(
        backgroundColor: Colors.red,
        backgroundImage: NetworkImage(gravatarUrl),
    ),
),
like image 177
Tirth Patel Avatar answered Nov 09 '22 02:11

Tirth Patel