How to search for user data and retrieve them from firebase with flutter?

1,518

To get the data you need to do the following:

  void getUserData() async{
    var firebaseUser = await FirebaseAuth.instance.currentUser();
    firestoreInstance.collection("users").document(firebaseUser.uid).get().then((value){
      print(value.data);
    });
  }

Assuming you are using Firebase authentication as the document id

Share:
1,518
omar developer
Author by

omar developer

Updated on December 21, 2022

Comments

  • omar developer
    omar developer over 1 year

    I am trying to retrieve user data that I stored on firebase database and compare it to an inputed text "trying to login but with another way ;)" but when I search for examples I can't quite understand their methods of retrieving data they don't retrieve specific data but the collection, so any ideas? enter image description here

  • omar developer
    omar developer about 4 years
    assumbtion = true :)
  • omar developer
    omar developer about 4 years
    But How can I get the email or the password after and store it in a const
  • Peter Haddad
    Peter Haddad about 4 years
    value.data will contain the email and password, you can do value.data["email"] and value.data[password"]
  • omar developer
    omar developer about 4 years
    about storing it
  • Peter Haddad
    Peter Haddad about 4 years
    store it to an instance variable and cal setState
  • omar developer
    omar developer about 4 years
    It's Ok now , Sorry false alarm.
  • omar developer
    omar developer about 4 years
    Can I change thw way to search for the document by replacing 'firebase.uid' with any thing else right
  • Peter Haddad
    Peter Haddad about 4 years
    if u have uid as a document id, then you need to use the above in the answer
  • omar developer
    omar developer about 4 years
    what about searching by the username that the user entered, Is it possible?
  • omar developer
    omar developer about 4 years
    Like storing the value of username in a controller and put the controller in firebase.uid
  • Peter Haddad
    Peter Haddad about 4 years
  • omar developer
    omar developer about 4 years
    What is a query?
  • omar developer
    omar developer about 4 years
    U seem like a smart guy :)