簡體   English   中英

如何從 Flutter 中的 Firestore 獲取錯誤

[英]How to get the error from Firestore in Flutter

在我的應用程序中,我有一個 Future Builder,等待從 Firestore 獲取數據。 現在,如果發生網絡問題,我想獲取錯誤類型( snapshot.hasError )以向用戶顯示。

我的未來建造者:

if (snapshot.hasData) {
          children = <Widget>[
            Container(
              child: color == null
                  ? new Container(
                      child: Html(
                      data: snapshot.data,
                    ))
                  : new Container(
                      child: Html(
                          data: snapshot.data,
                          style: {"html": Style(color: Color(color))}),
                    ),
            ),
          ];
        } else if (snapshot.hasError) {
          children = <Widget>[
            Icon(
              Icons.error_outline,
              color: Colors.red,
              size: 60,
            ),
            Padding(
              padding: const EdgeInsets.only(top: 16),
              child: Text(
                'Error: ${snapshot.error}',
                textAlign: TextAlign.center,
              ),
            )
          ];
        } else {
          children = <Widget>[
            CircularProgressIndicator(),
          ];
        }

隨意詢問其他信息。 謝謝你的幫助: :)

我在 GitHub 上發現了兩個問題( 12 ),它們已合並為一個問題 評論中解釋說這個問題已經解決並合並到master分支中。 根據此評論,它已於 7 月 14 日預發布。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM