firebase - 离线使用。 Flutter Hamilton 应用架构。写入节点并期望云函数更

以下引述摘自 Google 开发者博客。 https://developers.googleblog.com/2017/08/hamilton-app-takes-stage.html

For example, when someone enters the lottery, the app first writes data to specific nodes in Realtime Database and the database's security rules help to ensure that the data is valid. The write triggers a Cloud Function, which runs business logic and stores its result to a new node in the Realtime Database. The newly written result data is then pushed automatically to the app.

我了解,他们没有提出请求并期待请求,而是遵循以下模式:

  1. 写入实时数据库
  2. 写入触发 Action
  3. Action 触发一些逻辑和功能
  4. 函数将数据写回数据库
  5. 应用上的监听器收到关于 4 写入数据的通知。
  6. 应用更新 UI 或采取任何行动。

当有人参加比赛以获取门票时,Hamilton 应用会遵循这种模式。我对这种模式的主要担忧是,如果连接处于脱机状态,我们将不会得到结果,同时也不会出现错误。更改将在本地更新,firebase 将在下次有连接时更新,这会使事情变得困惑,因为用户期望得到结果。

我想知道是否有一种简单的方法或模式可以遵循,所以我们会得到一个错误并显示它。

我想到的第一个解决方案是以某种方式在保存操作上添加时间。如果在 x 秒内未在实时数据库上完成保存,则会显示错误。同时,我们还需要对回复进行超时。因此,如果我们在 x 秒内没有得到回复,我们会向用户显示一些内容。

我希望我不会感到困惑,因为我没有很好地理解这种模式。我为标题而苦苦挣扎,所以如果有人可以改进它,请成为我的客人。

最佳答案

即使构建了一个支持离线的应用程序,如果一个操作链依赖于一个云函数,我会让它在离线时无法执行,告诉用户在他在线时重试。 然而,这也可能导致糟糕的情况,因为您需要在用户每次尝试执行操作时检查连接,这可能会很痛苦。

关于firebase - 离线使用。 Flutter Hamilton 应用架构。写入节点并期望云函数更新数据库,然后监听更新 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50287887/

相关文章:

flutter - 保留选项卡 View 页面之间的状态

dart - Flutter中是否有可能 "extend"ThemeData

dart - 错误状态 : Mock method was not called within `w

flutter - 在 Flutter PageView 中切换页面时丢失小部件状态

ios - 如何在键盘外观上为 Flutter 布局设置动画

string - flutter/Dart : Convert HEX color string t

flutter - 在 FutureBuilder 中设置提供者值

android - Flutter:在 Android Studio 中打开 android 模块被

flutter - Flutter 目录不是 GitHub 项目的克隆

android - 为什么我的 Flutter 应用的 ListView 滚动不如 Flutter