import 'dart:async'; import 'package:flutter/services.dart'; class LocationBridge { static const MethodChannel _methodChannel = MethodChannel( 'com.traccar.client/tracking', ); static const EventChannel _eventChannel = EventChannel( 'com.traccar.client/location_updates', ); static Stream>? _locationStream; static Future startTracking() async { try { final result = await _methodChannel.invokeMethod('startTracking'); return result ?? false; } on PlatformException catch (e) { print('Failed to start tracking: ${e.message}'); return false; } } static Future stopTracking() async { try { final result = await _methodChannel.invokeMethod('stopTracking'); return result ?? false; } on PlatformException catch (e) { print('Failed to stop tracking: ${e.message}'); return false; } } static Future updateConfig(Map config) async { try { final result = await _methodChannel.invokeMethod( 'updateConfig', config, ); return result ?? false; } on PlatformException catch (e) { print('Failed to update config: ${e.message}'); return false; } } static Future?> getStatus() async { try { final result = await _methodChannel.invokeMethod('getStatus'); return result?.cast(); } on PlatformException catch (e) { print('Failed to get status: ${e.message}'); return null; } } static Stream> get locationUpdates { _locationStream ??= _eventChannel.receiveBroadcastStream().map( (event) => Map.from(event as Map), ); return _locationStream!; } }