【问题标题】:How can i display the firebase error message from terminal to UI?如何将 firebase 错误消息从终端显示到 UI?
【发布时间】:2021-02-13 15:16:26
【问题描述】:

我一直试图在安全区域内的列中显示此警报消息。我必须将此消息显示为错误消息,其中最初的 errormessage 是具有空值的字符串。错误信息在终端成功出现,但没有进入屏幕。

 try {

SharedPreferences 首选项 = 等待 SharedPreferences.getInstance();

  FirebaseAuth _auth = FirebaseAuth.instance;
  _auth
      .signInWithEmailAndPassword(
          email: username + '@mail.com', password: password)
      .then((log) {

    var key = prefs.setString('key', username);
    Navigator.pushAndRemoveUntil(
        context,
        MaterialPageRoute(builder: (BuildContext context) => Mails()),
        (Route<dynamic> route) => false);
  });
} catch (e) {
  showDialog(context: context, builder: (context) => Dialog(child: Text(e.toString()),));
  
  print('This is what we got ${e.message}');
}

这是我的调试控制台

E/flutter ( 3195): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 
Unhandled Exception: PlatformException(ERROR_USER_NOT_FOUND, There 
is no user record corresponding to this identifier. The user may 
have been deleted., null)
[38;5;244mE/flutter ( 3195): #0      
StandardMethodCodec.decodeEnvelope[39;49m
[38;5;244mE/flutter ( 3195): #1      
MethodChannel.invokeMethod[39;49m
E/flutter ( 3195): <asynchronous suspension>
[38;5;244mE/flutter ( 3195): #2       
MethodChannel.invokeMapMethod[39;49m
[38;5;248mE/flutter ( 3195): #3      
FirebaseAuth.signInWithCredential[39;49m
[38;5;248mE/flutter ( 3195): #4      
FirebaseAuth.signInWithEmailAndPassword[39;49m
[38;5;248mE/flutter ( 3195): #5      _LoginState.loginuser[39;49m
[38;5;244mE/flutter ( 3195): #6      _asyncThenWrapperHelper. 

(dart:async- 补丁/async_patch.dart:73:64)[39;49m [38;5;244mE/flutter (3195):#7 _rootRunUnary (dart:async/zone.dart:1134:38)[39;49m [38;5;244mE/flutter (3195):#8 _CustomZone.runUnary (dart:async/zone.dart:1031:19)[39;49m [38;5;244mE/flutter (3195):#9 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)[39;49m [38;5;244mE/flutter (3195):#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)[39;49m [38;5;244mE/flutter (3195): #11 Future._propagateToListeners (dart:async/future_impl.dart:709:32)[39;49m [38;5;244mE/颤振(3195):#12 Future._addListener。 (dart:async/future_impl.dart:389:9)[39;49m [38;5;244mE/flutter (3195):#13 _rootRun (dart:async/zone.dart:1126:13)[39;49m [38;5;244mE/flutter (3195):#14 _CustomZone.run (dart:async/zone.dart:1023:19)[39;49m [38;5;244mE/flutter (3195): #15 _CustomZone.runGuarded (dart:async/zone.dart:925:7)[39;49m [38;5;244mE/颤振(3195):#16 _CustomZone.bindCallbackGuarded。 (dart:async/zone.dart:965:23)[39;49m [38;5;244mE/flutter (3195):#17 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)[39;49m [38;5;244mE/flutter (3195):#18 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)[39;49m E/颤动​​(3195):

【问题讨论】:

    标签: firebase flutter firebase-authentication


    【解决方案1】:

    这样做

    catch(e){
      showDialog(
        context: context,
        builder: (context) => Dialog(child: Container(..<What you want to show>...)); );
    }
    

    你不需要 setState

    【讨论】:

    • 我试过了,但根本没用。错误出现在终端中,但不会作为对话框反映在 UI 中。不过感谢您的宝贵时间
    • 你能显示错误吗?你也试过e.toString()
    • 是的,我试过 .toString() 但没有用。我什至试图在 catch 块中打印一条甚至没有打印的虚拟消息。我不知道发生了什么。这是代码和调试控制台。
    • 我已经在上面发布了代码和调试控制台。请看一看。它甚至不打印打印语句。甚至错误都在抛出。
    • 当用户更新他们的电子邮件、密码或重置他们的密码时。 Firebase 身份验证后端会撤销他们的令牌,要求他们重新进行身份验证或尝试再次登录。这是一项安全功能。例如,如果他们的帐户被盗用,用户可以重置他们的密码。所有其他会话必须重新验证。这是因为与您登录/登录的电子邮件不存在,您必须使用 auth.createUserWithEmailAndPassword 注册该电子邮件,然后登录/注册或更正您的电子邮件和密码。
    猜你喜欢
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 2011-11-05
    • 2014-09-22
    • 2017-02-25
    • 1970-01-01
    相关资源
    最近更新 更多