firebase - 在颤动中从firebase获取日期并将其存储在var中
问题描述
有没有办法可以从 firebase 获取数据并将其存储为字符串,例如在颤振中?
我希望我的应用程序具有基于角色的用户,每个用户都有一个角色和一个页面。firebase 身份验证只有用户名和密码。在我的数据库中,我有用户集合,UID 用作文档的 ID,我想查询文档并获取角色值并将其作为字符串存储在变量中。 http://prntscr.com/kwcylt
Container(
height: 50.0,
child: Material(
borderRadius: BorderRadius.circular(20.0),
shadowColor: Colors.greenAccent,
color: Colors.green,
elevation: 7.0,
child: GestureDetector(
onTap: () {
FirebaseAuth.instance
.signInWithEmailAndPassword(
email: email,
password: password)
.then((FirebaseUser user) {
var userRole = Firestore.instance.collection('Users').document(user.uid).toString();
if(userRole['Role'].toString().compareTo("Admin"))
Navigator.of(context).pushReplacementNamed('/AdminTabs');
else Navigator.of(context).pushReplacementNamed('/UserTabs');
})
.catchError((e) {
print(e);
});
},
我希望 userRole 包含来自 firebase 的数据
解决方案
像这样更新您的代码,它将起作用:您基本上是在对文档引用而不是文档快照运行检查。
.then((FirebaseUser user) {
Firestore.instance.collection('Users')
.document('user.uid').get().then((userRole){
if(userRole['Role'].toString().contains("Admin")){
Navigator.of(context).pushReplacementNamed('/AdminTabs');
}
else {Navigator.of(context).pushReplacementNamed('/UserTabs');}
});
})
.catchError((e) {
print(e);
});
},
推荐阅读
- android - 使用 Textview 和 Spinner 和斜线进行布局
- r - R 数据框单元格包含数据框/小标题 - 如何访问或可视化?
- javascript - 检测用户是否验证了他们的电子邮件?
- windows - Windows 10 的 MFT 中如何处理 DOS 文件名?
- elasticsearch - 如何使用 ApolloQuery Vue 组件查询 Elasticsearch 端点?
- amazon-web-services - 我何时需要将 Kinesis Data Streams 与 Kinesis Firehose 结合使用?
- python - 熊猫在数据框中组合稀疏列
- c++ - 在 C++ 运行时更改类型的成员标识符
- c# - 使用任一验证文本框浮点输入。或者 ,
- javascript - Immutable JS - 如何在转换深度嵌套的 JS 对象时保留类型并获得不变性?