This is our second time using dart/flutter to create an iOS and Android app and I’d like advice on packages to help sync content so it is available when the app is disconnected.
Now that the MVP app is working when connected, a new requirement is that it also needs to work when the mobile device is not connected to either wifi or the phone network. Target users work in the bowels of large buildings with bad reception.
We therefore need to download to local stores on devices the app content including user specific content. The content is a combination of data from the db and image and audio files.
We are thinking of using SQLite locally. We expect the pattern will be to attempt to update the local stores in the background periodically especially when first logging in.
Are there packages that can help manage keeping the local file system up to date with files on a server?
Are there packages that would be appropriate for syncing between a server’s MySQL tables and local SQLite tables?
Please send me to a general resource if appropriate. FWIW, we contributed date_range_form_field | Flutter package during our first project though we generally develop websites with WordPress, Drupal and CiviCRM.
Your best bet is Hasura + PowerSync + SQLite (using Drift or PowerSync ORM).
Your database works 100% offline, all user data is synced automagically (you define the rules in PowerSync).
Writes are written in the SQLite local database and PowerSync will create batches for you with the changed data, so you can call your backend to save the data (I do generic GraphQL mutations, so the code is very simple).
It works wonderfully well. And all products can be hosted in docker. If you want a really cheap option and don’t mind bug hunting, nHost is a nice option (USD 25 for generous space and bandwidth, using Hasura + PostgreSQL).
Caveats:
All your records must have one and only one primary key named “Id”
All your data must, somehow, be connected to the authenticated user (of course, if the table is not public), but PowerSync doesn’t support joins or subqueries, so, you’ll have to create some helper tables binding data to users (ex.: each Order has a Customer (which is a user), each Order has many Products. Without joins, you cannot tell which Products are bound to the order’s Customer, so you’ll have to create a helper table OrderProducts_Customer in order to make Products available to PowerSync sync rules).
You might want to check out the following recordings from the latest Fluttercon. I think they were very insightful when it comes to offline-first in Flutter.
I think the synced databases approach explained by Simon (the author of Drift) could offer a very quick win if you don’t need to handle any specific processing
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape. Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.