小编Rob*_*isa的帖子

Flutter在尝试Firebase身份验证时无法捕获PlatformException

我最近才开始使用flutter,我正在尝试使用电子邮件和密码来实现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), …
Run Code Online (Sandbox Code Playgroud)

android exception firebase firebase-authentication flutter

5
推荐指数
2
解决办法
3149
查看次数