【发布时间】:2018-10-29 14:56:37
【问题描述】:
我最近才开始使用颤振,我正在尝试使用电子邮件和密码实现 Firebase 登录,当我输入正确的电子邮件和密码时它可以工作,但当密码错误时它不起作用。当密码错误时,它会给出一个 PlatformException,然后应用程序会冻结,即使我已经尝试捕获异常,而 android studio 显示如下:
这是我的登录实现:
String _reason;
Future<void> _performLogin() async {
String reason;
// This is just a demo, so no actual login here.
try{
FirebaseUser user = await FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password);
if(user != null){
Navigator.of(context).push(new MaterialPageRoute<dynamic>(
builder: (BuildContext context) {
return new MyApp();
},
));
final snack = new SnackBar(
content: new Text("Signed In Successfully"),
action: null,
duration: new Duration(seconds: 4),
backgroundColor: Colors.black,
);
Scaffold.of(context).showSnackBar(snack);
}
}on PlatformException catch(e){
reason = '${e.message}';
/*final snack = new SnackBar(
content: new Text(e.message),
action: null,
duration: new Duration(seconds: 4),
backgroundColor: Colors.black,
);
Scaffold.of(context).showSnackBar(snack);*/
}
setState(() {
_reason = reason;
});
}
我还加了import 'package:flutter/services.dart' show PlatformException;
请告诉我如何捕捉异常,谢谢。
【问题讨论】:
-
尝试在以后登录时添加
.catchError( -
@Tree 很遗憾没有工作。
-
我在另一项任务中遇到了同样的问题。我通过在我的代码中手动查找错误来解决它。尝试匿名登录,看看是否有效。在firebase中启用匿名唱歌。如果这也不起作用,则可能是您在应用程序中的 firebase 设置。比再次通过 firebase 上的 codelab 并再次配置您的应用程序。
标签: android firebase exception firebase-authentication flutter