【问题标题】:How to get the error from Firestore in Flutter如何在 Flutter 中从 Firestore 获取错误
【发布时间】:2020-12-08 01:10:51
【问题描述】:

在我的应用中,我有一个 Future Builder,正在等待从 Firestore 获取数据。 现在我想获取错误类型 (snapshot.hasError) 以显示用户,如果发生网络问题。

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

请随意询问更多信息。 谢谢你的帮助! :)

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    我在 GitHub 上发现了两个问题(12),它们已合并到 single issue 中。在comment 中解释了这个问题已经解决并合并到master 分支中。根据this comment,它已于 7 月 14 日预发布。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-08
      • 2022-01-17
      • 2021-07-17
      • 2021-10-13
      • 1970-01-01
      • 2020-12-04
      • 2019-07-26
      • 1970-01-01
      相关资源
      最近更新 更多