颤振更改Drawer UserAccountsDrawerHeader布局

时间:2020-02-19 15:45:53

标签: flutter dart header drawer

我正在构建我的第一个Flutter应用程序,所以我的问题是: 您是否可以更改UserAccountsDrawerHeader的个人资料图片的布局,例如下面的图像,我想将图像放在用户名的左侧

enter image description here

这是我的代码

class SideMenu extends StatefulWidget {
  SideMenu({Key key}) : super(key: key);

  @override
  _SideMenuState createState() => _SideMenuState();
}

class _SideMenuState extends State<SideMenu> {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        children: <Widget>[
          
          UserAccountsDrawerHeader(
            accountEmail: Text('@User'),
            accountName: Text('user'),
            currentAccountPicture: CircleAvatar(
              backgroundImage: AssetImage("assets/Images/profilePic.jpg"),
              
            ),
          ),

          ListTile(
            title: Text('hey'),
          )
        ],
       )
    );
  }
}

1 个答案:

答案 0 :(得分:0)

您可以通过将row Widget提供给accountName属性来实现,如以下代码所示。

UserAccountsDrawerHeader(
          accountEmail: Text(''), // keep blank text because email is required
          accountName: Row(
            children: <Widget>[
              Container(
                width: 50,
                height: 50,
                decoration: BoxDecoration(shape: BoxShape.circle),
                child: CircleAvatar(
                  backgroundColor: Colors.redAccent,
                  child: Icon(
                    Icons.check,
                  ),
                ),
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text('user'),
                  Text('@User'),
                ],
              ),
            ],
          ),
        ),