2

I am new to Flutter/Firebase and I want to program an app where a user can login/register and then he needs to create a profile with his information like his name, age... and only if he has created his profile, he should be able to continue and see the "main part" of the app.

I already implemented the Firebase Auth with a working Login / Register Page, but my question is now, how to create the Profile thing the most efficent.

At the moment I created this method here at my own:

  Future checkUserProfile() async{

// get snapshot from document
final snapShot = await Firestore.instance.collection('profiles').document(uid).get();

if(snapShot == null || !snapShot.exists){

  User.gotProfile = false;

} else {

  User.gotProfile = true;

}

This method is checking if an user-profile with the Firebase Auth User UID already exists and if not, the user will be send to the "ProfilePage" with a FutureBuilder executing the method above and if it already exists, he will see the main part of the app.

As I already said, I tried it by myself and I wanted to ask if this is already an good implementation or is there even an easier & better way to do it?

1 Answer 1

1

Yes this is an good implementation. In my app I have the check User method like yours. The following method is an example. When the user is not registered he forwarded to the RegisterPage else he forwarded to the MainPage.

checkUserAlreadyExists(FirebaseUser user) async {
    final userData = await Firestore.instance.collection('users').document(user.uid).get();
    if (userData == null || !userData.exists) {
      setState(() {
        Navigator.pushAndRemoveUntil(context,
            MaterialPageRoute(builder: (BuildContext context) => RegisterPage()), ModalRoute.withName('/'));
      });
    } else {
      setState(() {
        Navigator.pushAndRemoveUntil(context,
            MaterialPageRoute(builder: (BuildContext context) => MainPage()), ModalRoute.withName('/'));
      });
    }
  }
Sign up to request clarification or add additional context in comments.

2 Comments

Ahh okay, you did it already in the function. I created an extra widget for it, but it still should be the same. Thank you very much for sharing!
Yes exactly no problem you are welcome :) can you please accept the answer or can i help you with a other problem?

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.