I wanted to sync my local DB with my server. In Android we have sync Adapter that does the work and make life easier. I would wonder if we have something similar in Flutter or how can I do that in flutter.
Sync-adapters are core Android components. Flutter cannot directly provide a replacement for them. However, flutter does provide a mechanism to use platform specific APIs called flutter plugin
. And although their are a lot of plugins already present, their is still a bit lack of plugins providing such core platform support.
Ideally, in an android application, the sync adapters are background services which can be triggered by the OS itself in a separate process, so the simplest way would be to do the following :
Create a separate sync-adapter inside the android
directory of your flutter app. Make sure you correctly follow all the requirements for the sync-adapter to work. The documentation is in here.
Create a simple plugin-mechanism using this to invoke android APIs corresponding to the sync-adapter.
Also note that all this code - Android sync-adapter, flutter-plugin and your flutter-app, can simply reside in current code base. You are NOT REQUIRED to create a separate "plugin" to actually use the plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With