startService method

  1. @override
Future<bool> startService({
  1. required AndroidNotificationOptions androidNotificationOptions,
  2. required IOSNotificationOptions iosNotificationOptions,
  3. required ForegroundTaskOptions foregroundTaskOptions,
  4. required String notificationTitle,
  5. required String notificationText,
  6. Function? callback,
})
override

Implementation

@override
Future<bool> startService({
  required AndroidNotificationOptions androidNotificationOptions,
  required IOSNotificationOptions iosNotificationOptions,
  required ForegroundTaskOptions foregroundTaskOptions,
  required String notificationTitle,
  required String notificationText,
  Function? callback,
}) async {
  if (await isRunningService == false) {
    final options = Platform.isAndroid
        ? androidNotificationOptions.toJson()
        : iosNotificationOptions.toJson();
    options['notificationContentTitle'] = notificationTitle;
    options['notificationContentText'] = notificationText;
    if (callback != null) {
      options.addAll(foregroundTaskOptions.toJson());
      options['callbackHandle'] =
          PluginUtilities.getCallbackHandle(callback)?.toRawHandle();
    }
    return await methodChannel.invokeMethod('startService', options);
  }
  return false;
}