flutter - 在颤振中使用 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,
),
),
);
},
我使用中心小部件,但它不起作用。
解决方案
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
因为被包裹在Row
with otherAccountsPictures
(最多 3 个小部件)中。为此,您必须Drawer
自己自定义。
推荐阅读
- android - Android Vertical Pager Adapter(在寻呼机适配器之间添加不同的页面)
- continuous-integration - Team City 设置警告没有代理
- xml - Odoo 我想在向导中添加树视图
- javascript - 在 svg 中的饼图路径之间添加间隙
- javascript - javascript中图像的条件动态导入以进行反应
- database - PostgreSQL 数据库日志事务
- javascript - 使用 ajax 将动态数据填充到下拉列中的问题
- git - 如何在 git push 上将自定义参数传递给 jenkins 作业(多分支管道)?
- javascript - jquery UL LI 折叠它下面的所有展开子
- docker - Docker 堆栈内存预留