Failure from Workmanager flutter

34 views Asked by At

I am using the Workmanager plugin to execute a periodic task when the app is in foreground and background.

At times I will receive a notification, as it is when debug mode is true, with failure or something else which is not Success but in the android studio console there is not exception. It lets confused as I don't know what is causing the Workmanager to fail.

@pragma('vm:entry-point')
Future<void> callbackDispatcher() async {
  Workmanager().executeTask((task, inputData) async {
    if (WorkManagerSettings.taskKey == task) {
      try {
        ...my code;
      } catch (err) {
        debugPrintStack();
        throw Exception(err);
      }
    }
    return Future.value(true);
  });
}


await Workmanager().initialize(
        callbackDispatcher, // The top level function, aka callbackDispatcher
        isInDebugMode:
        true
    );
    await Workmanager().registerPeriodicTask(
      WorkManagerSettings.taskKey,
      WorkManagerSettings.taskKey,
      frequency: const Duration(minutes: 15),
      initialDelay: Duration.zero,
      existingWorkPolicy: ExistingWorkPolicy.replace,
    );
0

There are 0 answers