import re path = "packages/tactical_app/lib/controllers/tactical_map_controller.dart" with open(path, "r") as f: content = f.read() # Replace initGps with a stream version old_init_gps_start = " /// Initialize Live GPS Sensor" old_init_gps_end = " void switchMode" stream_gps = """ /// Initialize Live GPS Sensor / تهيئة حساس الموقع الجغرافي Future initGps() async { try { final serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) return; LocationPermission perm = await Geolocator.checkPermission(); if (perm == LocationPermission.denied) { perm = await Geolocator.requestPermission(); } if (perm == LocationPermission.whileInUse || perm == LocationPermission.always) { // 1. Get initial position and jump camera final pos = await Geolocator.getCurrentPosition( locationSettings: const LocationSettings( accuracy: LocationAccuracy.high, timeLimit: Duration(seconds: 5), ), ); currentGpsPosition.value = LatLng(pos.latitude, pos.longitude); currentCameraCenter.value = currentGpsPosition.value!; tracker.updateMyPosition(currentGpsPosition.value!, pos.heading); mapController?.animateCamera( CameraUpdate.newLatLngZoom(currentGpsPosition.value!, 14.0), ); // 2. Listen to continuous GPS updates for Blue Force Tracking Geolocator.getPositionStream( locationSettings: const LocationSettings( accuracy: LocationAccuracy.high, distanceFilter: 2, // update every 2 meters ), ).listen((Position newPos) { final latLng = LatLng(newPos.latitude, newPos.longitude); currentGpsPosition.value = latLng; tracker.updateMyPosition(latLng, newPos.heading); }); } } catch (e) { debugPrint('GPS init error: $e'); } } """ # Naive replacement idx_start = content.find(old_init_gps_start) idx_end = content.find(" /// Switch Tactical", idx_start) if idx_start != -1 and idx_end != -1: content = content[:idx_start] + stream_gps + content[idx_end:] with open(path, "w") as f: f.write(content)