0

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

Thanks in advance!

1 Answer 1

2

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

I suggest you to use Cloud Firestore

Because you can find all types of queries in this.

Cloud Firestore dependency

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks i followed your advice and turned into FirebaseFirestore, it worked out +Karma @priyesh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.