首页 > 解决方案 > 处理 Firebase_Auth 错误并在屏幕上显示错误

问题描述

我想处理 firebase_auth 异常并在屏幕上显示错误消息。我有几个关于在屏幕上显示错误消息的问题。

  1. 有什么东西可以自动显示消息吗?
  2. 还是我需要提供文本字段或标签来显示消息?

我正在使用最新的软件包:firebase_auth: ^3.0.1

这是我的登录代码:

RoundedButton(
                title: 'Log In',
                colour: Colors.lightBlueAccent,
                onPressed: () async {
                  setState(() {
                    showSpinner = true;
                  });
                  try {
                    UserCredential userCredential = await _auth.signInWithEmailAndPassword(email: email, password: password);
                  } on FirebaseAuthException catch (e) {
                    if (e.code == 'user-not-found') {
                      print('No user found for that email.');
                    } else if (e.code == 'wrong-password') {
                      print('Wrong password provided for that user.');
                    }
                  }
                },
              ),

这里一切正常,但我想显示错误消息而不是将它们放在控制台中。我该怎么做呢?

标签: flutterfirebase-authentication

解决方案


推荐阅读