I'm new to flutter and I'm trying to create a profile screen to get user data from firebase's real-time database like name, email, and phone number. I tried to search on google but all the examples I found are to get data from the Firestore database, not the real-time database. I would appreciate it if somebody helps me.
You need to do something like this:
Future<String> getUsername() async {
final ref = FirebaseDatabase.instance.reference();
User cuser = await firebaseAuth.currentUser;
return ref.child('User_data').child(cuser.uid).once().then((DataSnapshot snap) {
final String userName = snap.value['name'].toString();
print(userName);
return userName;
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.