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/…?Peter Haddad– Peter Haddad2018-07-26 08:14:00 +00:00Commented Jul 26, 2018 at 8:14
-
yes i am using that only.rannes– rannes2018-07-26 08:34:52 +00:00Commented 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.rannes– rannes2018-07-26 08:38:19 +00:00Commented Jul 26, 2018 at 8:38
Add a comment
|
1 Answer
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
3 Comments
rannes
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.
Peter Haddad
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
rannes
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.