start method
Future<void>
start({
- required LiveLocationConfig config,
- required void onLocation(),
- void onError(
- String error
Start live location tracking with server sync
Parameters:
config: Configuration for tracking and sync behavioronLocation: Callback invoked for each location updateonError: Optional callback invoked when errors occur
Throws StateError if already tracking Throws Exception if location permissions are denied
Implementation
Future<void> start({
required LiveLocationConfig config,
required void Function(LocationDto) onLocation,
void Function(String error)? onError,
}) async {
if (_isTracking) {
throw StateError('Location tracking is already active');
}
if (!_isInitialized) {
await initialize();
}
_currentConfig = config;
_onLocation = onLocation;
_onError = onError;
try {
// Register location updates with the native service
await BackgroundLocator.registerLocationUpdate(
_handleLocationUpdate,
initCallback: _handleInit,
initDataCallback: config.toMap(),
disposeCallback: _handleDispose,
androidSettings: config.androidSettings,
iosSettings: config.iosSettings,
);
_isTracking = true;
debugPrint('Live location tracking started');
} catch (e) {
_onError?.call('Failed to start tracking: $e');
debugPrint('Failed to start location tracking: $e');
rethrow;
}
}