繁体   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