-
Notifications
You must be signed in to change notification settings - Fork 49
Flutter background processing
Matej Drobnič edited this page Dec 28, 2020
·
3 revisions
Since most of the watch logic is being executed in the background when the app is not open, Cobble also has background flutter side. All code in the background folder is executed in the separate isolate.
How background works:
- When user opens app normally,
BackgroundSetupControl().setupBackgroundis called. This sends method reference of themain_backgroundto the native side via Flutter. Native saves that reference. - When background service of the app starts by the native side, separate flutter instance is created and previously-saved reference to the main_background is executed.
-
main_backgroundregisters all needed pigeon callbacks - Whenever some event that needs processing occurs (for example when user changes his/hers calendar and needs sync), native sends pigeon to the background Flutter instance.
Notes:
- Background instance is completely isolated from the UI flutter instance. No variables or object instances are shared.
- To send messages from UI to background isolate, UI must send a pigeon to the native which then proxies the message back to the background isolate
- Due to SQLite's spotty support for multiple isolates, database is read-only from the UI isolate. If UI needs to change the database it needs to send a message to it through above mentioned process.