startLocationUpdates method

Future<void> startLocationUpdates({
  1. required String httpsUrl,
  2. Duration interval = const Duration(seconds: 15),
  3. Map<String, String>? headers,
  4. Map<String, dynamic>? metadata,
  5. int maxQueueSize = 200,
  6. Duration initialBackoff = const Duration(seconds: 3),
  7. Duration maxBackoff = const Duration(seconds: 60),
  8. String? authRefreshUrl,
  9. Map<String, String>? authRefreshHeaders,
  10. Map<String, dynamic>? authRefreshBody,
  11. String authTokenResponseKey = 'accessToken',
  12. String authHeaderName = 'Authorization',
  13. String authHeaderPrefix = 'Bearer ',
})

Starts periodic background location uploads to the configured HTTPS endpoint.

Implementation

Future<void> startLocationUpdates({
  required String httpsUrl,
  Duration interval = const Duration(seconds: 15),
  Map<String, String>? headers,
  Map<String, dynamic>? metadata,
  int maxQueueSize = 200,
  Duration initialBackoff = const Duration(seconds: 3),
  Duration maxBackoff = const Duration(seconds: 60),
  String? authRefreshUrl,
  Map<String, String>? authRefreshHeaders,
  Map<String, dynamic>? authRefreshBody,
  String authTokenResponseKey = 'accessToken',
  String authHeaderName = 'Authorization',
  String authHeaderPrefix = 'Bearer ',
}) async {
  if (!httpsUrl.startsWith('https://')) {
    throw ArgumentError('Only HTTPS endpoints are allowed.');
  }

  if (authRefreshUrl != null && !authRefreshUrl.startsWith('https://')) {
    throw ArgumentError('authRefreshUrl must be HTTPS when provided.');
  }

  final int intervalMs =
      interval.inMilliseconds < 5000 ? 5000 : interval.inMilliseconds;
  final int initialBackoffMs = initialBackoff.inMilliseconds < 1000
      ? 1000
      : initialBackoff.inMilliseconds;
  final int maxBackoffMs = maxBackoff.inMilliseconds < initialBackoffMs
      ? initialBackoffMs
      : maxBackoff.inMilliseconds;

  await _channel.invokeMethod('startLocationUpdates', {
    'url': httpsUrl,
    'intervalMs': intervalMs,
    'headers': headers ?? <String, String>{},
    'metadata': metadata ?? <String, dynamic>{},
    'maxQueueSize': maxQueueSize < 10 ? 10 : maxQueueSize,
    'initialBackoffMs': initialBackoffMs,
    'maxBackoffMs': maxBackoffMs,
    'authRefreshUrl': authRefreshUrl,
    'authRefreshHeaders': authRefreshHeaders ?? <String, String>{},
    'authRefreshBody': authRefreshBody ?? <String, dynamic>{},
    'authTokenResponseKey': authTokenResponseKey,
    'authHeaderName': authHeaderName,
    'authHeaderPrefix': authHeaderPrefix,
  });
}