简体   繁体   English

如何从 Flutter 中的 Firestore 获取错误

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

In my app, I have a Future Builder, waiting for fetched Data from Firestore.在我的应用程序中,我有一个 Future Builder,等待从 Firestore 获取数据。 Now I want to get the error type ( snapshot.hasError ) to show the user, if a network problem occured.现在,如果发生网络问题,我想获取错误类型( snapshot.hasError )以向用户显示。

My FutureBuilder:我的未来建造者:

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(),
          ];
        }

Fell free to ask for additional Information.随意询问其他信息。 Thanks for your help: :)谢谢你的帮助: :)

I have found two issues ( 1 and 2 ) reporting this on GitHub that have been merged into a single issue .我在 GitHub 上发现了两个问题( 12 ),它们已合并为一个问题 In a comment it is explained that this issue has already been solved and merged into the master branch.评论中解释说这个问题已经解决并合并到master分支中。 As per this comment it was pre-released on the 14th of July.根据此评论,它已于 7 月 14 日预发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM