首页 > 解决方案 > 在颤振中使用 UserAccountsDrawerHeader 时,如何将头像图像居中对齐?

问题描述

当我想在flutter endDrawer中使用UserAccountsDrawerHeader时,如何设置所有头像图像和accountEmail和accountName在抽屉中心对齐,在我的代码中每件事都在左边对齐?

这是我的代码:

endDrawer: Drawer(
            child: BackdropFilter(
              filter: ImageFilter.blur(
                sigmaX: 1.8,
                sigmaY: 1.8,
              ),
              child: Column(
                children: <Widget>[
              Center( child:
              UserAccountsDrawerHeader(
                accountEmail: Text(
                user.email ?? "user Email",
                style: TextStyle(
                    color: Theme
                        .of(context)
                        .colorScheme
                        .onPrimary),
              ),
              accountName: Text(
                user.fullName ?? user.username ?? "user Name",
                style: TextStyle(
                    color: Theme
                        .of(context)
                        .colorScheme
                        .onPrimary),
              ),
              currentAccountPicture: GestureDetector(
                onTap: () {},
                child: Container(
                    child: InkWell(
                      onTap: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(
                            builder: (context) => ProfileScreen(
                              user: user,
                            ),
                          ),
                        );
                      },

我使用中心小部件,但它不起作用。

标签: flutterdartdrawer

解决方案


mam_65尝试将它们包装在Row

...    
child: UserAccountsDrawerHeader(
       accountEmail: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        user.email ?? "user Email",
                        style: TextStyle(
                            color: Theme.of(context).colorScheme.onPrimary),
                      ),
                    ],
                  ),
        accountName: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        user.fullName ?? user.username ?? "user Name",
                        style: TextStyle(
                            color: Theme.of(context).colorScheme.onPrimary),
                      ),
                    ],
                  ),
...

注意:无法居中currentAccountPicture因为被包裹在Rowwith otherAccountsPictures(最多 3 个小部件)中。为此,您必须Drawer自己自定义。


推荐阅读