flutter_foreground_task
flutter_foreground_task copied to clipboard
Persisting complex objects
I'd like to ask for some advice rather than raising an issue. In my application I'm getting a lot of info from a server and based on that I build complex objects and structures. When using the app, everything works okay (of course), but I do not know how I could best persist this complex object between the foregroundtask calls when the main app is closed. Storing it with saveData and getData is very cumbersome, as the objects are quite complex, so I would like to avoid it.
Is there a way to e.g. store the object in the task handler and when e.g. I open the application again, just pass the references back? (I'm not even speaking about the periodic task I need to do, which would also go with the update of these objects, I would really-really like to avoid constant serialization/deserialization, if possible. :/ )
TL;DR: You have no other choice!
All other methods of persisting data (in flutter) have some kind of dependency on the widget bindings the you have no access to it inside foreground tasks isolate. And only thing that you can use are the FlutterForegroundTask.getData() & FlutterForegroundTask.saveData() methods. So json serialization is the only way to go.
TL;DR: You have no other choice!
All other methods of persisting data (in flutter) have some kind of dependency on the widget bindings the you have no access to it inside foreground tasks isolate. And only thing that you can use are the
FlutterForegroundTask.getData()&FlutterForegroundTask.saveData()methods. So json serialization is the only way to go.
Not necessarily, Isar would work just fine even inside the isolate. Take a look at it. Objectbox would work fine as well.