【问题标题】:How to display user role on a drawer flutter如何在抽屉颤动中显示用户角色
【发布时间】:2024-05-01 10:50:02
【问题描述】:

我目前在用户登录后在我的抽屉上显示电子邮件和姓名。角色存储在 Firestore 中。

我想显示用户角色,例如“免费或 VIP” 但我找不到适合UserAccountsDrawerHeader Widget 的属性有什么想法吗?

UserAccountsDrawerHeader(
                      accountName: Text(
                        _name,
                        style: TextStyle(
                            fontFamily: FontFamily.elgantfamily,
                            fontWeight: FontWeight.bold),
                      ),
                      accountEmail: Text(
                        _email,
                        style:
                            TextStyle(fontFamily: FontFamily.elgantfamily),
                      ),
                      accountRole: Text(
                      _role,
                      style: TextStyle(
                        fontFamily: FontFamily.elgantfamily,
                        fontWeight: FontWeight.bold),
                       ),
),

_getUserNameandEmail() async {
String uid = await GetStorage().read(sharedPrefrenceKey.uuid);
if (uid != null) {
  _name = GetStorage().read(sharedPrefrenceKey.name);
  _email = GetStorage().read(sharedPrefrenceKey.email);
  _role = GetStorage().read(sharedPrefrenceKey.role);
  setState(() {});
}
}

【问题讨论】:

  • 设计您自己的自定义标题
  • 一些例子将不胜感激

标签: flutter dart navigation-drawer sidebar user-roles


【解决方案1】:

如果你真的想使用UserAccountsDrawerHeader,你可以这样做

UserAccountsDrawerHeader(
                accountName: Text('User Name'),
                accountEmail: Text('Email'),
              otherAccountsPictures: [
                Text(
                  'Role',style: TextStyle(
                  color: Colors.red
                ),
                )
              ],
            )

【讨论】: