When I initialize the work manager in my Flutter Application it crashes.
WorkManager Code
Workmanager().initialize(
callbackDispatcher,
isInDebugMode: true
);
Workmanager().registerPeriodicTask(
"2",
"simplePeriodicTask",
frequency: Duration(minutes: 15),
);
//callbackDispatcher
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
log("Native called background task"); //simpleTask will be emitted here.
return Future.value(true);
});
}
I understand there might be many reasons for it including Kotlin version compatibility and Flutter version compatibility among many, but this is what worked for me.
At another area of the app, I invoked
For some reason, just removing that line from the app fixed the issue. I tried relocating it as an action button to a different page or even a call from the onDispose override function, but for some reason, as long as this line exists somewhere in the code, it keeps crashing.
So i just removed it completely and I used server API calls to make sure that new periodic instances aren't being created on initializing the WorkManager on each app open.
Hope this helps.