flutter - 如何从firebase颤振中检索当前用户字段
问题描述
我试图通过使用 FutureBuilder 从 firebase 获取当前用户的一些信息。但它告诉我错误说
return new Scaffold(
body: FutureBuilder(
future: FirebaseFirestore.instance
.collection('Users').where('email', isEqualTo: FirebaseAuth.instance.currentUser.email).get(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
} else if (snapshot.connectionState == ConnectionState.done) {
print(snapshot.data.docs.length);
return Container(
child: ListView(children: <Widget>[
ListTile(
leading: Icon(Icons.person),
title: Text("Name: " +
snapshot.data.docs[0].get('Name') +
"\n" +
"Civil ID: " +
snapshot.data.docs[0].get('Civil ID')),
subtitle: Text(snapshot.data.docs[0].get('email')),
),
解决方案
Try this
FirebaseAuth auth = FirebaseAuth.instance;
return new Scaffold(
body: FutureBuilder(
future: FirebaseFirestore.instance
.collection('Users').where('email', isEqualTo: auth.currentUser.email).get(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
} else if (snapshot.connectionState == ConnectionState.done) {
print(snapshot.data.docs.length);
return Container(
child: ListView(children: <Widget>[
ListTile(
leading: Icon(Icons.person),
title: Text("Name: " +
snapshot.data.docs[0].get('Name') +
"\n" +
"Civil ID: " +
snapshot.data.docs[0].get('Civil ID')),
subtitle: Text(snapshot.data.docs[0].get('email')),
),
//If that don't work, you might have to upload a picture of how you structured your database
推荐阅读
- php - 在 Laravel 6 中进行插入的最佳方法
- google-apps-script - GAS - 获取所有命名范围的脚本,包括受保护的范围 - 没有工作
- teamcity - 如何为 teamcity 代理安装附加软件?
- c# - c#中如何获取当前正在执行的方法的返回类型和返回类型的泛型?
- sql - 如何找到第二个和最大日期并比较这两个
- laravel - Laravel如何删除默认刀片
- r - R 绘图标题包含一个 url,但 pdf 导出中的超链接不起作用(“404”页面)
- javascript - Windows 应用程序可以让浏览器知道它的存在吗?
- python - 如何在Python中删除两个双括号之间的文本
- clickhouse - Superset 无法访问 ClickHouse 数据库