Node.js 检查Flatter应用程序中Firebase Auth中是否已存在电子邮件

Node.js 检查Flatter应用程序中Firebase Auth中是否已存在电子邮件,node.js,firebase,flutter,dart,firebase-realtime-database,Node.js,Firebase,Flutter,Dart,Firebase Realtime Database,它在通过电子邮件和密码注册时有效,但当我使用已注册的id注册时,它不会显示错误。相反,它重定向到主页,并在控制台中显示PlatformException(错误\u EMAIL\u已在使用中,电子邮件地址已被另一个帐户使用 Future validateForm() async { FormState formState = _formKey.currentState; if (formState.validate()) { FirebaseUser user = await firebase

它在通过电子邮件和密码注册时有效,但当我使用已注册的id注册时,它不会显示错误。相反,它重定向到主页,并在控制台中显示
PlatformException(错误\u EMAIL\u已在使用中,电子邮件地址已被另一个帐户使用

Future validateForm() async {
FormState formState = _formKey.currentState;
if (formState.validate()) {
  FirebaseUser user = await firebaseAuth.currentUser();
  if (user == null) {
    firebaseAuth
        .createUserWithEmailAndPassword(
            email: _emailTextController.text,
            password: _passwordTextController.text)
        .then((user) => {
              _userServices.createUser(user.user.uid, {
                "username": _nameTextController.text,
                "email": _emailTextController.text,
                "userId": user.user.uid,
                "gender": gender,
              }),
            })
        .catchError((err) {
      showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text("User Already Exists"),
              content: Text(err.message),
              actions: [
                FlatButton(
                  child: Text("Ok"),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                )
              ],
            );
          });
    });
    Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => HomePage()));
  } else {
    return ("already a user");
  }
}

}您将进入第二页,因为您有:

   Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => HomePage()));
if
块之后。因此,如果
user==null
它将输入
if
,然后进入
catchError
内部,然后导航到
主页
,您应该将上述代码移动到
其他

  } else {
  Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => HomePage()));
    return ("already a user");
  }

让我们看看我的数据库代码导入'包:firebase_database/firebase_database.dart';class UserServices{FirebaseDatabase\u database=FirebaseDatabase.instance;String ref=“users”;createUser(String uid,Map value){u database.reference().child($ref/$uid”).set(value).catchError((e)=>{print(e.toString())};}