【发布时间】:2021-02-18 10:46:56
【问题描述】:
如果用户未注册,则调用signInWithEmailAndPassword 时,应用会崩溃。
我使用 try and catch 来避免它,但似乎没用。
更改数千次后,错误始终相同:
PlatformException (PlatformException(user-not-found, There is no user record corresponding to this identifier. The user may have been deleted.
我正在使用Form 来获取用户输入,也许这就是问题所在?
顺便说一下,在下面的代码中,我手动插入了电子邮件和密码,所以我认为它不关心Forms。
这是代码:
FirebaseAuth auth = FirebaseAuth.instance;
showErrDialog(BuildContext context, String err) {
FocusScope.of(context).requestFocus(new FocusNode());
return showDialog(
context: context,
child: AlertDialog(
title: Text("Error"),
content: Text(err),
actions: <Widget>[
OutlineButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Ok"),
),
],
),
);
}
Future<User> signin(
String email, String password, BuildContext context) async {
await Firebase.initializeApp();
try {
UserCredential result =
await auth.signInWithEmailAndPassword(email: email, password: email);
User user = result.user;
return Future.value(user);
} catch (e) {
print(e.code);
switch (e.code) {
case 'ERROR_INVALID_EMAIL':
showErrDialog(context, e.code);
break;
case 'ERROR_WRONG_PASSWORD':
showErrDialog(context, e.code);
break;
case 'ERROR_USER_NOT_FOUND':
showErrDialog(context, e.code);
break;
case 'ERROR_USER_DISABLED':
showErrDialog(context, e.code);
break;
case 'ERROR_TOO_MANY_REQUESTS':
showErrDialog(context, e.code);
break;
case 'ERROR_OPERATION_NOT_ALLOWED':
showErrDialog(context, e.code);
break;
}
调用者:
onPressed: () => signin("go@gmail.com", "ciaollllL1", context),
【问题讨论】:
-
你用的是什么IDE?
-
Visual Studio 代码
标签: firebase flutter firebase-authentication