Offline Usage. Flutter Hamilton App Architecture. Write to Node and Expect Cloud Function to Update Database and then listener to update UI
Asked Answered
E

1

6

The following quote is taken from Google Developer Blog. 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.

I understand that instead of making a request and expecting a request, they followed the following pattern:

  1. Write to real-time database
  2. The write trigger an action
  3. The action triggers some logic and function
  4. The function writes data back to the database
  5. The listener on the app gets a notification about the data written on 4.
  6. App updates UI or takes whatever action.

Hamilton app followed this pattern when someone enters the competition for a ticket. My main concern with the pattern is that if the connection is offline, we won't get results and at the same time we won't get an error. The changes will be updated locally and firebase will update the next time there is a connection, which will make things messy, as the user is expecting a result.

I was wondering if there is an easy way or a pattern to follow, so we will get an error and display it.

The first solution that comes to my mind is to somehow add a time on the save operation. If the save is not done on the live database within x seconds then we display an error. At the same time, we will also need a timeout on the reply. So if we do not get a reply within x seconds we display something to the user.

I hope I am not confused as I did not understand the pattern well. I struggled with the title, so if anyone can improve it, please be my guest.

Eatable answered 11/5, 2018 at 8:11 Comment(2)
Did you ever find some example code on how to do this pattern? Also did you get a good answer for the offline question you had? Just saw the demo video from GDC and got interesting in trying it outSherfield
Unfortunately not. Can you please upvote so it get a bit more attention.Eatable
H
0

Even building an offline capable app, if an operations chain relies on a Cloud Function, I'd make it impossible to execute while offline, telling user to retry when he's online. However this might lead to bad situations as well because you need to check connection every time the user tries to execute the ops, which might be painful.

Heigl answered 24/11, 2018 at 19:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.