updateService static method

Future<bool> updateService({
  1. String? notificationTitle,
  2. String? notificationText,
  3. Function? callback,
})

Update the foreground service.

Implementation

static Future<bool> updateService({
  String? notificationTitle,
  String? notificationText,
  Function? callback,
}) async {
  // If the service is not running, the update function is not executed.
  if (!await isRunningService) return false;

  final options = <String, dynamic>{};
  options['notificationContentTitle'] = notificationTitle;
  options['notificationContentText'] = notificationText;
  if (callback != null) {
    options['callbackHandle'] =
        PluginUtilities.getCallbackHandle(callback)?.toRawHandle();
  }

  final bool result =
      await _methodChannel.invokeMethod('updateForegroundService', options);
  if (result) {
    _printMessage('FlutterForegroundTask has updated.');
    return true;
  }

  return false;
}