我有一个关于 try/catch with dart 的小问题。
如何添加脚本以检查我的函数 SignUp 中是否已存在伪代码?
_signUp(String _email, String _password, String _pseudo) async {
try {
//Create Get Firebase Auth User
if (_formKey.currentState.validate()) {
await auth.createUserWithEmailAndPassword(
email: _email, password: _password);
//problem here
users.get().then((querySnapshot) {
querySnapshot.docs.forEach((result) {
var pseudoDoc = result.data()['pseudo'];
if (pseudoDoc != _pseudo) {
users.doc(auth.currentUser.uid).set({
'pseudo': _pseudo,
'email': _email,
});
} else {
throw 'Pseudo already exist';
}
});
});
//
}
} on FirebaseAuthException catch (error) {
CoolAlert.show(
context: context,
type: CoolAlertType.error,
text: error.message,
);
}
}
}```