1

I try to experience Firebase Live database with flutter. i would like get values from firebase database based on userid. that means if user login with a mail he needs to his details based on his userid. can anyone help me in these.

3
  • are you using this github.com/flutter/plugins/tree/master/packages/…? Commented Jul 26, 2018 at 8:14
  • yes i am using that only. Commented Jul 26, 2018 at 8:34
  • i am trying to know ! how to get data based on userid in firebase database. i am done with with storing data in database. now i would like to login with email and by that basing on it data needs to get based on that mail userid. i tried to do research , but i didnot found any examples on these. Commented Jul 26, 2018 at 8:38

1 Answer 1

1

If you have this database:

users
 userId
    mail: [email protected]
    name: userx

Then to get data based on userId, try the following:

 final FirebaseDatabase database = new FirebaseDatabase(app: widget.app);
 _messagesRef = database.reference().child('users');

_messageRef.orderByKey().equalTo(userId).once().then((DataSnapshot snapshot) {
  print('Connected to the database and read ${snapshot.value}');
});

First configure the database, then reference the location, and use the query orderByKey() to be able to get the data based on the userId provided.

Check the example here:

https://github.com/flutter/plugins/blob/master/packages/firebase_database/example/lib/main.dart#L60

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

3 Comments

thank you @peterHaddad . i had already done with it. my problem is if i login with email i need to save user personal data and based on user email_useid(uid) i need fetch data fro database. i am having little bit confusion in these.
in the answer above you are fetching the data based on the userid, you should use the database structure that I wrote in the answer
i ll look after it. but i my question is see if user login with email and password for first time at that moment we are saving our information in database if user logged second time that stored data have to be displayed . like that we are having many users so in that case basing firebaseuserid of email i need to fetch data.

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.