restartService static method

Future<ReceivePort?> restartService()

Restart the foreground service. The option value uses the option value of the currently running service as it is.

Implementation

static Future<ReceivePort?> restartService() async {
  if (!await isRunningService) {
    throw const ForegroundTaskException(
        'There are no service started or running.');
  }

  final receivePort = _registerPort();
  if (receivePort == null) {
    throw const ForegroundTaskException(
        'Failed to register SendPort to communicate with background isolate.');
  }

  final bool result =
      await _methodChannel.invokeMethod('restartForegroundService');
  if (result) {
    _printMessage('FlutterForegroundTask has restarted.');
    return receivePort;
  }

  return null;
}