无法更改UserAccountsDrawerHeader背景

时间:2019-03-29 15:13:24

标签: dart flutter

我正在尝试将Drawer中的UserAccountsDrawerHeader背景从浅蓝色更改为另一种颜色,但找不到解决方案。谁能帮我吗?

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

1 个答案:

答案 0 :(得分:0)

由于未指定decoration属性,因此将颜色设置为主题的默认primaryColor。使用decoration属性设置颜色。

UserAccountsDrawerHeader(
    decoration: BoxDecoration(
        color: Colors.red,
    ),
    accountName: Text(sessionUsername),
    accountEmail: Text(mail),
    currentAccountPicture: CircleAvatar(
        backgroundColor: Colors.red,
        backgroundImage: NetworkImage(gravatarUrl),
    ),
),