Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error : display a red line under this statement _userFromFirebaseUser(userCredential.user);

hi every one I’m trying making my app with flutter . it is contains a sign up page so I write the code and I’m retrieving an information from the firebase after I upload it .

the below code is the sign up code

UserModel? _userFromFirebaseUser(User userCredential) {
    return userCredential != null
        ? UserModel(
            id: userCredential.uid,
            bannerImageUrl: '',
            name: '',
            email: '',
            profileImageUrl: '')
        : null;
  }

  Stream<UserModel?> get userCredential {
    return auth
        .authStateChanges()
        .map((userCredential) => _userFromFirebaseUser(userCredential!));
  }

  Future SignUp(email, password) async {
    var formdata = formstate.currentState;

    if (formdata!.validate()) {
      print("valid");
      formdata.save();
      try {
        UserCredential userCredential =
            (await auth.createUserWithEmailAndPassword(
                email: myemail!, password: mypassword!));

        FirebaseFirestore.instance
            .collection('Users')
            .doc(userCredential.user!.uid)
            .set({'name': email, 'email': email});
        _userFromFirebaseUser(userCredential.user);

        return userCredential;
      } on FirebaseAuthException catch (e) {
        if (e.code == 'weak-password') {
          Navigator.of(context).pop();
          print('The password provided is too weak.');
        } else if (e.code == 'email-already-in-use') {
          Navigator.of(context).pop();
          print('The account already exists for that email.');
        }
      } catch (e) {
        print(e);
      }
    } else {}
  }

and the red line appears on this line _userFromFirebaseUser(userCredential.user); as it is appears in the picture . please help me

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

userCredential.user      is User? not User

change the method parameter

UserModel? _userFromFirebaseUser(User? userCredential) {
    return ....
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading