Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Is there anything similar to sync adapter in flutter

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.

like image 884
vikas pandey Avatar asked Nov 06 '22 12:11

vikas pandey


1 Answers

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 :

  1. 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.

  2. 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.

like image 120
zeekhuge Avatar answered Nov 14 '22 23:11

zeekhuge