无法从Firebase DB接收和存储特定数据的值-Flutter [英] Cannot receive and store value of the specific data from Firebase DB - Flutter

查看:36
本文介绍了无法从Firebase DB接收和存储特定数据的值-Flutter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从FirebaseDatabase检索和存储单个数据时遇到问题.在监视列表上进行调试期间,我将快照的值设置为null.我需要从数据库获取当前用户的城市名称.

I'm having an issue with retrieving and storing single data from FirebaseDatabase. During the debugging on my watch list i get value of the snapshot as null. I need to get city name of the current user from db.

  void addToFb() async {
    final User user = FirebaseAuth.instance.currentUser;
    final uid = user.uid;
    final city = await FirebaseDatabase.instance
      .reference()
      .child('Users')
      .equalTo(uid)
      .once()
      .then((DataSnapshot snapshot) {
        var temp = snapshot.value.city;
        return temp;
      });

以防万一我的数据库看起来像这样:

Just in case my database looks like this:

 - Users
 |- uid
 ||- name
 ...
 ||- city

提前谢谢!

推荐答案

这不是解决方案,而是为了简化代码和数据库结构,

This is not the solution but for make your code and db structure easy,

我建议您使用 Cloud Firestore

因为您可以在其中找到所有类型的查询.

Because you can find all types of queries in this.

Cloud Firestore 依赖性

这篇关于无法从Firebase DB接收和存储特定数据的值-Flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆