颤动/飞镖& Firebase错误消息&代码

时间:2018-06-18 15:30:24

标签: firebase error-handling dart flutter future

我正在将Firebase Auth实施到我的Flutter应用中。如何从Firebase访问错误代码或用户友好的错误消息?这可用吗?

例如,在iOS上,您可以从错误中获取localisedDescription

在Dart中,我有一个onError:catchError期货,它们会返回一个错误对象,但似乎没有相关的相关信息。

1 个答案:

答案 0 :(得分:1)

可用。问题是catchError值不是对象,因此您无法通过其键循环。 print / debugPrint仅输出值,而没有给您任何提示如何仅引用其中一个的线索。

它具有getter方法-代码,消息和...详细信息。 'details'是人类可读的结果,但是在firebase_auth flutter示例中没有记录。做到这一点:

<!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Voice Controlled Notes App</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src='https://code.responsivevoice.org/responsivevoice.js'></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/shoelace-css/1.0.0-beta16/shoelace.css">
        <link rel="stylesheet" href="styles.css">

    </head>
    <body>
        <div class="container">

            <h1>Voice Controlled Notes App</h1>
            <p class="page-description">A tiny app that allows you to take notes by recording your voice</p>
            <h3 class="no-browser-support">Sorry, Your Browser Doesn't Support the Web Speech API. Try Opening This Demo In Google Chrome.</h3>

            <div class="app"> 
                <h3>Add New Note</h3>
                <div class="input-single">
                    <textarea id="note-textarea" placeholder="Input." rows="6"></textarea>
                </div>
                <button id="start-record-btn" title="Start Recording">Start Recognition</button>         
                <button id="pause-record-btn" onClick="myFunction()" title="Pause Recording">Stop listening</button>
                <p id="recording-instructions">Press the <strong>Start Recognition</strong> button and allow access.</p>
                
            </div>

        </div>
        

        <p id="demo"></p>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="script.js"></script>

        <script>

            function myFunction() {
                var str = document.getElementById("note-textarea").value;
                if (str.includes("hello how are you")){
                    document.getElementById("demo").innerHTML = "hi anthony";
                    responsiveVoice.speak("I am good thanks,       and you?");
                }
            }
        </script>
    </body>
</html>