flutter - 在flutter中使用UserAccountsDrawerHeader时如何将头像图像居中对齐?

标签 flutter dart drawer

当我想在 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,
                            ),
                          ),
                        );
                      },

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

最佳答案

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 居中,因为它与 otherAccountsPictures 一起包装在 Row 中(最多 3 个)小部件)。为此,您必须自己自定义一个抽屉

关于flutter - 在flutter中使用UserAccountsDrawerHeader时如何将头像图像居中对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64858443/

相关文章:

android - 如何在 Android 中完全隐藏抽屉式汉堡包?

android - Flutter:当小部件树被锁定时调用 setState() 或 markNeedsBuild() ... 在方向更改期间

flutter - RenderFlex溢出- flutter

mongodb - 两次调用Future后出现NoSuchMethodError

reactjs - 无法在react应用程序中使用Ant design的Drawer

dart - 我如何创建一个新的子类扩展一个ButtonElement

Flutter ListView 构建器滚动 Controller 监听器未在 ListView 内触发?

flutter - 让小部件比视口(viewport)更大?

swift - 用 switch 或 if-else 替换 guard

flutter - 您如何组合 2 Riverpod StreamProvider,其中 1 个流取决于来自另一个流的数据?