Home > database >  The email address is badly formatted - Flutter firebase
The email address is badly formatted - Flutter firebase

Time:05-02

FirebaseAuthException ([firebase_auth/invalid-email] The email address is badly formatted

when I uses flutter firebase email password auth it shows email adress badly formated. name and vehicle number is also pass to the database when authentication process is there any problem in it. why it occurs. if someone can help me to find out the problem help me

    MaterialButton(
                              shape: RoundedRectangleBorder(
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(20.0))),
                              elevation: 5.0,
                              height: 40,
                              onPressed: () {
                                setState(() {
                                  showProgress = true;
                                });
                                signUp(
                                    emailController.text,
                                    passwordController.text,
                                    role,
                                    vehicleNo.text,
                                    name.text);
                              },
                              child: Text(
                                "Register",
                                style: TextStyle(
                                  fontSize: 20,
                                ),
                              ),
                              color: Colors.white,
                            )
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  void signUp(String name, String email, String password, String role,
      String vehicleNo) async {
    const CircularProgressIndicator();
    if (_formkey.currentState!.validate()) {
      await _auth
          .createUserWithEmailAndPassword(
              email: email.trim(), password: password.trim())
          .then(
            (value) => {
              postDetailsToFirestore(
                email,
                role,
                name,
                vehicleNo,
              ),
            },
          )
          .catchError((e) {
        print("its an error");
      });
    }
  }

  postDetailsToFirestore(
      String email, String role, String name, String vehicleNo) async {
    FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
    User? user = _auth.currentUser;
    UserModel userModel = UserModel();
    userModel.email = email;
    userModel.name = name;
    userModel.vehicleNo = vehicleNo;
    userModel.uid = user!.uid;
    userModel.role = role;
    await firebaseFirestore
        .collection("users")
        .doc(user.uid)
        .set(userModel.toMap());

    Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => LoginScreen()));
  }
}

CodePudding user response:

When executing the SignUp function (at Material Button OnPressed), are the variables passed in the wrong order?

CodePudding user response:

It's almost always trailing whitespace, try:

postDetailsToFirestore(
            email.trim(),
            role,
            name,
            vehicleNo,
          ),

Alternatively you can also try to hardcode the right email address and check whether the problem is in logic or in UI.

  • Related