首页 > 解决方案 > Flutter Firebase try catch 不触发

问题描述

当使用 firebase auth 并输入未注册的电子邮件时,虽然我使用了 try-catch,但不会触发。
fAuth.signInWithEmailAndPassword肯定会抛出 PlatformException 但该代码没有捕捉到这一点。
我遇到这个问题大约 2 天.....请帮助我

在此处输入图像描述

Future<bool> signInWithEmail(String email, String password) async {
    try {
      var result = await fAuth.signInWithEmailAndPassword(
          email: email, password: password);
      if (result != null) {
        setUser(result.user);
        FirebaseFirestore.instance.collection("User").doc(_user.uid).get().then((doc) {
          info.set(
              name: doc["name"],
              email: doc["email"],
              phoneNumber: doc["phoneNumber"],
              follower: doc["follower"],
              following: doc["following"],
              like: doc["like"],
              review: doc["review"],
              visited: doc["visited"],
              favorite: doc["favorite"],
            );
            print(doc['name']);
            notifyListeners();
        });
        return true;
      }
      return false;
    } on PlatformException catch (e) {
      List<String> result = e.toString().split(", ");
      setLastFBMessage(result[1]);
      return false;
    } on Exception catch (e) {
      List<String> result = e.toString().split(", ");
      setLastFBMessage(result[1]);
      return false;
    } catch (e) {
      List<String> result = e.toString().split(", ");
      setLastFBMessage(result[1]);
      return false;
    }
  }

标签: firebaseflutterdart

解决方案


推荐阅读