initialize method

Future<void> initialize(
  1. Function callbackDispatcher, {
  2. bool isInDebugMode = false,
})

This call is required if you wish to use the WorkManager plugin. callbackDispatcher is a top level function which will be invoked by Android or iOS. See the discussion on BackgroundTaskHandler for details. isInDebugMode true will post debug notifications with information about when a task should have run

Implementation

Future<void> initialize(
  final Function callbackDispatcher, {
  final bool isInDebugMode = false,
}) async {
  Workmanager._isInDebugMode = isInDebugMode;
  final callback = PluginUtilities.getCallbackHandle(callbackDispatcher);
  assert(callback != null,
      "The callbackDispatcher needs to be either a static function or a top level function to be accessible as a Flutter entry point.");
  if (callback != null) {
    final int handle = callback.toRawHandle();
    await _foregroundChannel.invokeMethod<void>(
      'initialize',
      JsonMapperHelper.toInitializeMethodArgument(
        isInDebugMode: _isInDebugMode,
        callbackHandle: handle,
      ),
    );
  }
}