当我想在 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/