Compare commits

...

5 Commits

Author SHA1 Message Date
stopflock
6363cabacf roadmap 2025-12-12 17:53:09 -06:00
stopflock
5312456a15 Better location / gps maybe 2025-12-12 16:26:50 -06:00
stopflock
8493679526 Nodes stay dimmed while one is selected 2025-12-11 20:30:14 -06:00
stopflock
2047645e89 clean up debug logging 2025-12-11 16:46:43 -06:00
stopflock
656dbc8ce8 positioning tutorial 2025-12-11 16:01:45 -06:00
20 changed files with 659 additions and 68 deletions

View File

@@ -242,6 +242,10 @@ Users expect instant response to their actions. By immediately updating the cach
- **Orange ring**: Node currently being edited
- **Red ring**: Nodes pending deletion
**Node dimming behavior:**
- **Dimmed (50% opacity)**: Non-selected nodes when a specific node is selected for tag viewing, or all nodes during search/navigation modes
- **Selection persistence**: When viewing a node's tag sheet, other nodes remain dimmed even when the map is moved, until the sheet is closed (v2.1.3+ fix)
**Direction cone visual states:**
- **Full opacity**: Active session direction (currently being edited)
- **Reduced opacity (40%)**: Inactive session directions

View File

@@ -98,27 +98,25 @@ cp lib/keys.dart.example lib/keys.dart
## Roadmap
### Needed Bugfixes
- Clean cache when nodes have been deleted by others
- Are offline areas preferred for fast loading even when online? Check working.
### Current Development
- Optional reason message when deleting
- Option to import profiles from deflock identify page?
- Import/Export map providers, profiles (profiles from deflock identify page?)
### On Pause
- Import/Export map providers, profiles
- Clean cache when nodes have been deleted by others
- Improve offline area node refresh live display
- Offline navigation (pending vector map tiles)
### Future Features & Wishlist
- Update offline area nodes while browsing?
- Offline navigation (pending vector map tiles)
- Android Auto / CarPlay
- Optional reason message when deleting
- Update offline area data while browsing?
### Maybes
- Yellow ring for devices missing specific tag details
- "Cache accumulating" offline area
- "Offline areas" as tile provider
- Grab the full latest database for each profile just like for suspected locations (instead of overpass)
- Android Auto / CarPlay
- "Cache accumulating" offline area?
- "Offline areas" as tile provider?
- Grab the full latest database for each profile just like for suspected locations (instead of overpass)?
- Optional custom icons for profiles to aid identification
- Custom device providers and OSM/Overpass alternatives
- Offer options for extracting nodes which are attached to a way/relation:

View File

@@ -1,4 +1,18 @@
{
"2.1.3": {
"content": [
"• Fixed nodes losing their greyed-out appearance when map is moved while viewing a node's tag sheet",
"• Improved GPS location handling - follow-me button is now greyed out when location is unavailable",
"• Added approximate location fallback - if precise location is denied, app will use approximate location",
"• Higher frequency GPS updates when follow-me modes are active for smoother tracking (1-second updates vs 5-second)"
]
},
"2.1.2": {
"content": [
"• New positioning tutorial - first-time users must drag the map to refine location when creating or editing nodes, helping ensure accurate positioning",
"• Tutorial automatically dismisses after moving the map at least 1 meter and never shows again"
]
},
"2.1.0": {
"content": [
"• Profile tag refinement system - any profile tag with an empty value now shows a dropdown in refine tags",

View File

@@ -56,6 +56,10 @@ class AppState extends ChangeNotifier {
late final UploadQueueState _uploadQueueState;
bool _isInitialized = false;
// Positioning tutorial state
LatLng? _tutorialStartPosition; // Track where the tutorial started
VoidCallback? _tutorialCompletionCallback; // Callback when tutorial is completed
Timer? _messageCheckTimer;
AppState() {
@@ -437,6 +441,11 @@ class AppState extends ChangeNotifier {
target: target,
refinedTags: refinedTags,
);
// Check tutorial completion if position changed
if (target != null) {
_checkTutorialCompletion(target);
}
}
void updateEditSession({
@@ -455,6 +464,11 @@ class AppState extends ChangeNotifier {
extractFromWay: extractFromWay,
refinedTags: refinedTags,
);
// Check tutorial completion if position changed
if (target != null) {
_checkTutorialCompletion(target);
}
}
// For map view to check for pending snap backs
@@ -462,6 +476,40 @@ class AppState extends ChangeNotifier {
return _sessionState.consumePendingSnapBack();
}
// Positioning tutorial methods
void registerTutorialCallback(VoidCallback onComplete) {
_tutorialCompletionCallback = onComplete;
// Record the starting position when tutorial begins
if (session?.target != null) {
_tutorialStartPosition = session!.target;
} else if (editSession?.target != null) {
_tutorialStartPosition = editSession!.target;
}
}
void clearTutorialCallback() {
_tutorialCompletionCallback = null;
_tutorialStartPosition = null;
}
void _checkTutorialCompletion(LatLng newPosition) {
if (_tutorialCompletionCallback == null || _tutorialStartPosition == null) return;
// Calculate distance moved
final distance = Distance();
final distanceMoved = distance.as(LengthUnit.Meter, _tutorialStartPosition!, newPosition);
if (distanceMoved >= kPositioningTutorialMinMovementMeters) {
// Tutorial completed! Mark as complete and notify callback immediately
final callback = _tutorialCompletionCallback;
clearTutorialCallback();
callback?.call();
// Mark as complete in background (don't await to avoid delays)
ChangelogService().markPositioningTutorialCompleted();
}
}
void addDirection() {
_sessionState.addDirection();
}

View File

@@ -126,6 +126,10 @@ const Duration kProximityAlertCooldown = Duration(minutes: 10); // Cooldown betw
// Node proximity warning configuration (for new/edited nodes that are too close to existing ones)
const double kNodeProximityWarningDistance = 15.0; // meters - distance threshold to show warning
// Positioning tutorial configuration
const double kPositioningTutorialBlurSigma = 3.0; // Blur strength for sheet overlay
const double kPositioningTutorialMinMovementMeters = 1.0; // Minimum map movement to complete tutorial
// Navigation route planning configuration
const double kNavigationMinRouteDistance = 100.0; // meters - minimum distance between start and end points
const double kNavigationDistanceWarningThreshold = 20000.0; // meters - distance threshold for timeout warning (30km)

View File

@@ -446,6 +446,11 @@
"dontShowAgain": "Diese Anleitung nicht mehr anzeigen",
"gotIt": "Verstanden!"
},
"positioningTutorial": {
"title": "Position verfeinern",
"instructions": "Ziehen Sie die Karte, um die Geräte-Markierung präzise über dem Standort des Überwachungsgeräts zu positionieren.",
"hint": "Sie können für bessere Genauigkeit vor der Positionierung hineinzoomen."
},
"navigation": {
"searchLocation": "Ort suchen",
"searchPlaceholder": "Orte oder Koordinaten suchen...",

View File

@@ -37,6 +37,11 @@
"dontShowAgain": "Don't show this guide again",
"gotIt": "Got It!"
},
"positioningTutorial": {
"title": "Refine Your Location",
"instructions": "Drag the map to position the device marker precisely over the surveillance device's location.",
"hint": "You can zoom in for better accuracy before positioning."
},
"actions": {
"tagNode": "New Node",
"download": "Download",

View File

@@ -37,6 +37,11 @@
"dontShowAgain": "No mostrar esta guía otra vez",
"gotIt": "¡Entendido!"
},
"positioningTutorial": {
"title": "Refinar Ubicación",
"instructions": "Arrastra el mapa para posicionar el marcador del dispositivo con precisión sobre la ubicación del dispositivo de vigilancia.",
"hint": "Puedes acercar el zoom para obtener mejor precisión antes de posicionar."
},
"actions": {
"tagNode": "Nuevo Nodo",
"download": "Descargar",

View File

@@ -37,6 +37,11 @@
"dontShowAgain": "Ne plus afficher ce guide",
"gotIt": "Compris !"
},
"positioningTutorial": {
"title": "Affiner la Position",
"instructions": "Faites glisser la carte pour positionner le marqueur de l'appareil précisément au-dessus de l'emplacement du dispositif de surveillance.",
"hint": "Vous pouvez zoomer pour une meilleure précision avant de positionner."
},
"actions": {
"tagNode": "Nouveau Nœud",
"download": "Télécharger",

View File

@@ -37,6 +37,11 @@
"dontShowAgain": "Non mostrare più questa guida",
"gotIt": "Capito!"
},
"positioningTutorial": {
"title": "Affinare la Posizione",
"instructions": "Trascina la mappa per posizionare il marcatore del dispositivo precisamente sopra la posizione del dispositivo di sorveglianza.",
"hint": "Puoi ingrandire per una maggiore precisione prima di posizionare."
},
"actions": {
"tagNode": "Nuovo Nodo",
"download": "Scarica",

View File

@@ -37,6 +37,11 @@
"dontShowAgain": "Não mostrar este guia novamente",
"gotIt": "Entendi!"
},
"positioningTutorial": {
"title": "Refinar Posição",
"instructions": "Arraste o mapa para posicionar o marcador do dispositivo precisamente sobre a localização do dispositivo de vigilância.",
"hint": "Você pode aumentar o zoom para melhor precisão antes de posicionar."
},
"actions": {
"tagNode": "Novo Nó",
"download": "Baixar",

View File

@@ -37,6 +37,11 @@
"dontShowAgain": "不再显示此指南",
"gotIt": "明白了!"
},
"positioningTutorial": {
"title": "精确定位",
"instructions": "拖动地图将设备标记精确定位在监控设备的位置上。",
"hint": "您可以在定位前放大地图以获得更高的精度。"
},
"actions": {
"tagNode": "新建节点",
"download": "下载",

View File

@@ -433,16 +433,18 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
IconButton(
tooltip: _getFollowMeTooltip(appState.followMeMode),
icon: Icon(_getFollowMeIcon(appState.followMeMode)),
onPressed: () {
final oldMode = appState.followMeMode;
final newMode = _getNextFollowMeMode(oldMode);
debugPrint('[HomeScreen] Follow mode changed: $oldMode$newMode');
appState.setFollowMeMode(newMode);
// If enabling follow-me, retry location init in case permission was granted
if (newMode != FollowMeMode.off) {
_mapViewKey.currentState?.retryLocationInit();
}
},
onPressed: _mapViewKey.currentState?.hasLocation == true
? () {
final oldMode = appState.followMeMode;
final newMode = _getNextFollowMeMode(oldMode);
debugPrint('[HomeScreen] Follow mode changed: $oldMode$newMode');
appState.setFollowMeMode(newMode);
// If enabling follow-me, retry location init in case permission was granted
if (newMode != FollowMeMode.off) {
_mapViewKey.currentState?.retryLocationInit();
}
}
: null, // Grey out when no location
),
AnimatedBuilder(
animation: LocalizationService.instance,
@@ -490,11 +492,24 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
_isNodeLimitActive = isLimited;
});
},
onLocationStatusChanged: () {
// Re-render when location status changes (for follow-me button state)
setState(() {});
},
onUserGesture: () {
_mapInteractionHandler.handleUserGesture(
context: context,
onSelectedNodeChanged: (id) => setState(() => _selectedNodeId = id),
);
// Only clear selected node if tag sheet is not open
// This prevents nodes from losing their grey-out when map is moved while viewing tags
if (_sheetCoordinator.tagSheetHeight == 0) {
_mapInteractionHandler.handleUserGesture(
context: context,
onSelectedNodeChanged: (id) => setState(() => _selectedNodeId = id),
);
} else {
// Tag sheet is open - only handle suspected location clearing, not node selection
final appState = context.read<AppState>();
appState.clearSuspectedLocationSelection();
}
if (appState.followMeMode != FollowMeMode.off) {
appState.setFollowMeMode(FollowMeMode.off);
}

View File

@@ -16,6 +16,7 @@ class ChangelogService {
static const String _lastSeenVersionKey = 'last_seen_version';
static const String _hasSeenWelcomeKey = 'has_seen_welcome';
static const String _hasSeenSubmissionGuideKey = 'has_seen_submission_guide';
static const String _hasCompletedPositioningTutorialKey = 'has_completed_positioning_tutorial';
Map<String, dynamic>? _changelogData;
bool _initialized = false;
@@ -82,6 +83,18 @@ class ChangelogService {
await prefs.setBool(_hasSeenSubmissionGuideKey, true);
}
/// Check if user has completed the positioning tutorial
Future<bool> hasCompletedPositioningTutorial() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool(_hasCompletedPositioningTutorialKey) ?? false;
}
/// Mark that user has completed the positioning tutorial
Future<void> markPositioningTutorialCompleted() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_hasCompletedPositioningTutorialKey, true);
}
/// Check if app version has changed since last launch
Future<bool> hasVersionChanged() async {
final prefs = await SharedPreferences.getInstance();

View File

@@ -11,12 +11,81 @@ import '../services/changelog_service.dart';
import 'refine_tags_sheet.dart';
import 'proximity_warning_dialog.dart';
import 'submission_guide_dialog.dart';
import 'positioning_tutorial_overlay.dart';
class AddNodeSheet extends StatelessWidget {
class AddNodeSheet extends StatefulWidget {
const AddNodeSheet({super.key, required this.session});
final AddNodeSession session;
@override
State<AddNodeSheet> createState() => _AddNodeSheetState();
}
class _AddNodeSheetState extends State<AddNodeSheet> {
bool _showTutorial = false;
bool _isCheckingTutorial = true;
@override
void initState() {
super.initState();
_checkTutorialStatus();
}
Future<void> _checkTutorialStatus() async {
final hasCompleted = await ChangelogService().hasCompletedPositioningTutorial();
if (mounted) {
setState(() {
_showTutorial = !hasCompleted;
_isCheckingTutorial = false;
});
// If tutorial should be shown, register callback with AppState
if (_showTutorial) {
final appState = context.read<AppState>();
appState.registerTutorialCallback(_hideTutorial);
}
}
}
/// Listen for tutorial completion from AppState
void _onTutorialCompleted() {
_hideTutorial();
}
/// Also check periodically if tutorial was completed by another sheet
void _recheckTutorialStatus() async {
if (_showTutorial) {
final hasCompleted = await ChangelogService().hasCompletedPositioningTutorial();
if (hasCompleted && mounted) {
setState(() {
_showTutorial = false;
});
}
}
}
void _hideTutorial() {
if (mounted && _showTutorial) {
setState(() {
_showTutorial = false;
});
}
}
@override
void dispose() {
// Clear tutorial callback when widget is disposed
if (_showTutorial) {
try {
context.read<AppState>().clearTutorialCallback();
} catch (e) {
// Context might be unavailable during disposal, ignore
}
}
super.dispose();
}
void _checkProximityAndCommit(BuildContext context, AppState appState, LocalizationService locService) {
_checkSubmissionGuideAndProceed(context, appState, locService);
}
@@ -40,14 +109,14 @@ class AddNodeSheet extends StatelessWidget {
void _checkProximityOnly(BuildContext context, AppState appState, LocalizationService locService) {
// Only check proximity if we have a target location
if (session.target == null) {
if (widget.session.target == null) {
_commitWithoutCheck(context, appState, locService);
return;
}
// Check for nearby nodes within the configured distance
final nearbyNodes = NodeCache.instance.findNodesWithinDistance(
session.target!,
widget.session.target!,
kNodeProximityWarningDistance,
);
@@ -220,6 +289,7 @@ class AddNodeSheet extends StatelessWidget {
Navigator.pop(context);
}
final session = widget.session;
final submittableProfiles = appState.enabledProfiles.where((p) => p.isSubmittable).toList();
final allowSubmit = appState.isLoggedIn &&
submittableProfiles.isNotEmpty &&
@@ -246,7 +316,11 @@ class AddNodeSheet extends StatelessWidget {
}
}
return Column(
return Stack(
clipBehavior: Clip.none,
fit: StackFit.loose,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 12),
@@ -374,6 +448,14 @@ class AddNodeSheet extends StatelessWidget {
),
const SizedBox(height: 20),
],
),
// Tutorial overlay - show only if tutorial should be shown and we're done checking
if (!_isCheckingTutorial && _showTutorial)
Positioned.fill(
child: PositioningTutorialOverlay(),
),
],
);
},
);

View File

@@ -13,12 +13,64 @@ import 'refine_tags_sheet.dart';
import 'advanced_edit_options_sheet.dart';
import 'proximity_warning_dialog.dart';
import 'submission_guide_dialog.dart';
import 'positioning_tutorial_overlay.dart';
class EditNodeSheet extends StatelessWidget {
class EditNodeSheet extends StatefulWidget {
const EditNodeSheet({super.key, required this.session});
final EditNodeSession session;
@override
State<EditNodeSheet> createState() => _EditNodeSheetState();
}
class _EditNodeSheetState extends State<EditNodeSheet> {
bool _showTutorial = false;
bool _isCheckingTutorial = true;
@override
void initState() {
super.initState();
_checkTutorialStatus();
}
Future<void> _checkTutorialStatus() async {
final hasCompleted = await ChangelogService().hasCompletedPositioningTutorial();
if (mounted) {
setState(() {
_showTutorial = !hasCompleted;
_isCheckingTutorial = false;
});
// If tutorial should be shown, register callback with AppState
if (_showTutorial) {
final appState = context.read<AppState>();
appState.registerTutorialCallback(_hideTutorial);
}
}
}
void _hideTutorial() {
if (mounted && _showTutorial) {
setState(() {
_showTutorial = false;
});
}
}
@override
void dispose() {
// Clear tutorial callback when widget is disposed
if (_showTutorial) {
try {
context.read<AppState>().clearTutorialCallback();
} catch (e) {
// Context might be unavailable during disposal, ignore
}
}
super.dispose();
}
void _checkProximityAndCommit(BuildContext context, AppState appState, LocalizationService locService) {
_checkSubmissionGuideAndProceed(context, appState, locService);
}
@@ -43,9 +95,9 @@ class EditNodeSheet extends StatelessWidget {
void _checkProximityOnly(BuildContext context, AppState appState, LocalizationService locService) {
// Check for nearby nodes within the configured distance, excluding the node being edited
final nearbyNodes = NodeCache.instance.findNodesWithinDistance(
session.target,
widget.session.target,
kNodeProximityWarningDistance,
excludeNodeId: session.originalNode.id,
excludeNodeId: widget.session.originalNode.id,
);
if (nearbyNodes.isNotEmpty) {
@@ -217,6 +269,7 @@ class EditNodeSheet extends StatelessWidget {
Navigator.pop(context);
}
final session = widget.session;
final submittableProfiles = appState.enabledProfiles.where((p) => p.isSubmittable).toList();
final isSandboxMode = appState.uploadMode == UploadMode.sandbox;
final allowSubmit = kEnableNodeEdits &&
@@ -245,7 +298,11 @@ class EditNodeSheet extends StatelessWidget {
}
}
return Column(
return Stack(
clipBehavior: Clip.none,
fit: StackFit.loose,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 12),
@@ -447,6 +504,14 @@ class EditNodeSheet extends StatelessWidget {
),
const SizedBox(height: 20),
],
),
// Tutorial overlay - show only if tutorial should be shown and we're done checking
if (!_isCheckingTutorial && _showTutorial)
Positioned.fill(
child: PositioningTutorialOverlay(),
),
],
);
},
);
@@ -456,7 +521,7 @@ class EditNodeSheet extends StatelessWidget {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => AdvancedEditOptionsSheet(node: session.originalNode),
builder: (context) => AdvancedEditOptionsSheet(node: widget.session.originalNode),
);
}
}

View File

@@ -15,29 +15,91 @@ import '../../models/node_profile.dart';
class GpsController {
StreamSubscription<Position>? _positionSub;
LatLng? _currentLatLng;
bool _hasLocation = false;
Timer? _retryTimer;
/// Get the current GPS location (if available)
LatLng? get currentLocation => _currentLatLng;
/// Whether we currently have a valid GPS location
bool get hasLocation => _hasLocation;
/// Initialize GPS location tracking
Future<void> initializeLocation() async {
final perm = await Geolocator.requestPermission();
if (perm == LocationPermission.denied ||
perm == LocationPermission.deniedForever) {
debugPrint('[GpsController] Location permission denied');
// Check if location services are enabled first
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
debugPrint('[GpsController] Location services disabled');
_hasLocation = false;
_scheduleRetry();
return;
}
_positionSub = Geolocator.getPositionStream().listen((Position position) {
final latLng = LatLng(position.latitude, position.longitude);
_currentLatLng = latLng;
debugPrint('[GpsController] GPS position updated: ${latLng.latitude}, ${latLng.longitude}');
});
final perm = await Geolocator.requestPermission();
debugPrint('[GpsController] Location permission result: $perm');
if (perm == LocationPermission.denied ||
perm == LocationPermission.deniedForever) {
debugPrint('[GpsController] Precise location permission denied, trying approximate location');
// Try approximate location as fallback
try {
await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
timeLimit: const Duration(seconds: 10),
);
debugPrint('[GpsController] Approximate location available, proceeding with location stream');
// If we got here, approximate location works, continue with stream setup below
} catch (e) {
debugPrint('[GpsController] Approximate location also unavailable: $e');
_hasLocation = false;
_scheduleRetry();
return;
}
} else if (perm == LocationPermission.whileInUse || perm == LocationPermission.always) {
debugPrint('[GpsController] Location permission granted: $perm');
// Permission is granted, continue with normal setup
} else {
debugPrint('[GpsController] Unexpected permission state: $perm');
_hasLocation = false;
_scheduleRetry();
return;
}
_positionSub?.cancel(); // Cancel any existing subscription
debugPrint('[GpsController] Starting GPS position stream');
_positionSub = Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 5, // Update when moved at least 5 meters (standard frequency)
),
).listen(
(Position position) {
final latLng = LatLng(position.latitude, position.longitude);
_currentLatLng = latLng;
if (!_hasLocation) {
debugPrint('[GpsController] GPS location acquired');
}
_hasLocation = true;
_cancelRetry(); // Got location, stop retrying
debugPrint('[GpsController] GPS position updated: ${latLng.latitude}, ${latLng.longitude} (accuracy: ${position.accuracy}m)');
},
onError: (error) {
debugPrint('[GpsController] Position stream error: $error');
if (_hasLocation) {
debugPrint('[GpsController] GPS location lost, starting retry attempts');
}
_hasLocation = false;
_currentLatLng = null;
_scheduleRetry(); // Lost location, start retrying
},
);
}
/// Retry location initialization (e.g., after permission granted)
Future<void> retryLocationInit() async {
debugPrint('[GpsController] Retrying location initialization');
debugPrint('[GpsController] Manual retry of location initialization');
_cancelRetry(); // Cancel automatic retries, this is a manual retry
await initializeLocation();
}
@@ -50,6 +112,9 @@ class GpsController {
}) {
debugPrint('[GpsController] Follow-me mode changed: $oldMode$newMode');
// Restart position stream with appropriate frequency for new mode
_restartPositionStream(newMode);
// Only act when follow-me is first enabled and we have a current location
if (newMode != FollowMeMode.off &&
oldMode == FollowMeMode.off &&
@@ -98,6 +163,8 @@ class GpsController {
}) {
final latLng = LatLng(position.latitude, position.longitude);
_currentLatLng = latLng;
_hasLocation = true;
_cancelRetry(); // Got location, stop any retries
// Notify that location was updated (for setState, etc.)
onLocationUpdated();
@@ -169,38 +236,184 @@ class GpsController {
VoidCallback? onMapMovedProgrammatically,
}) async {
final perm = await Geolocator.requestPermission();
if (perm == LocationPermission.denied ||
perm == LocationPermission.deniedForever) {
debugPrint('[GpsController] Location permission denied');
// Check if location services are enabled first
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
debugPrint('[GpsController] Location services disabled');
_hasLocation = false;
_scheduleRetry();
return;
}
_positionSub = Geolocator.getPositionStream().listen((Position position) {
// Get the current follow-me mode from the app state each time
final currentFollowMeMode = getCurrentFollowMeMode();
final proximityAlertsEnabled = getProximityAlertsEnabled();
final proximityAlertDistance = getProximityAlertDistance();
final nearbyNodes = getNearbyNodes();
final enabledProfiles = getEnabledProfiles();
processPositionUpdate(
position: position,
followMeMode: currentFollowMeMode,
controller: controller,
onLocationUpdated: onLocationUpdated,
proximityAlertsEnabled: proximityAlertsEnabled,
proximityAlertDistance: proximityAlertDistance,
nearbyNodes: nearbyNodes,
enabledProfiles: enabledProfiles,
onMapMovedProgrammatically: onMapMovedProgrammatically,
);
final perm = await Geolocator.requestPermission();
debugPrint('[GpsController] Location permission result: $perm');
if (perm == LocationPermission.denied ||
perm == LocationPermission.deniedForever) {
debugPrint('[GpsController] Precise location permission denied, trying approximate location');
// Try approximate location as fallback
try {
await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
timeLimit: const Duration(seconds: 10),
);
debugPrint('[GpsController] Approximate location available, proceeding with location stream');
// If we got here, approximate location works, continue with stream setup below
} catch (e) {
debugPrint('[GpsController] Approximate location also unavailable: $e');
_hasLocation = false;
_scheduleRetry();
return;
}
} else if (perm == LocationPermission.whileInUse || perm == LocationPermission.always) {
debugPrint('[GpsController] Location permission granted: $perm');
// Permission is granted, continue with normal setup
} else {
debugPrint('[GpsController] Unexpected permission state: $perm');
_hasLocation = false;
_scheduleRetry();
return;
}
_positionSub?.cancel(); // Cancel any existing subscription
debugPrint('[GpsController] Starting GPS position stream');
_positionSub = Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 5, // Update when moved at least 5 meters (standard frequency)
),
).listen(
(Position position) {
if (!_hasLocation) {
debugPrint('[GpsController] GPS location acquired');
}
_hasLocation = true;
_cancelRetry(); // Got location, stop retrying
// Get the current follow-me mode from the app state each time
final currentFollowMeMode = getCurrentFollowMeMode();
final proximityAlertsEnabled = getProximityAlertsEnabled();
final proximityAlertDistance = getProximityAlertDistance();
final nearbyNodes = getNearbyNodes();
final enabledProfiles = getEnabledProfiles();
processPositionUpdate(
position: position,
followMeMode: currentFollowMeMode,
controller: controller,
onLocationUpdated: onLocationUpdated,
proximityAlertsEnabled: proximityAlertsEnabled,
proximityAlertDistance: proximityAlertDistance,
nearbyNodes: nearbyNodes,
enabledProfiles: enabledProfiles,
onMapMovedProgrammatically: onMapMovedProgrammatically,
);
},
onError: (error) {
debugPrint('[GpsController] Position stream error: $error');
if (_hasLocation) {
debugPrint('[GpsController] GPS location lost, starting retry attempts');
}
_hasLocation = false;
_currentLatLng = null;
onLocationUpdated(); // Notify UI that location was lost
_scheduleRetry(); // Lost location, start retrying
},
);
}
/// Schedule periodic retry attempts to get location
void _scheduleRetry() {
_retryTimer?.cancel();
_retryTimer = Timer.periodic(const Duration(seconds: 15), (timer) {
debugPrint('[GpsController] Automatic retry of location initialization (attempt ${timer.tick})');
initializeLocation(); // This will cancel the timer if successful
});
}
/// Cancel any scheduled retry attempts
void _cancelRetry() {
if (_retryTimer != null) {
debugPrint('[GpsController] Canceling location retry timer');
_retryTimer?.cancel();
_retryTimer = null;
}
}
/// Restart position stream with frequency optimized for follow-me mode
void _restartPositionStream(FollowMeMode followMeMode) {
if (_positionSub == null || !_hasLocation) {
// No active stream or no location - let normal initialization handle it
return;
}
_positionSub?.cancel();
// Use higher frequency when follow-me is enabled
if (followMeMode != FollowMeMode.off) {
debugPrint('[GpsController] Starting high-frequency GPS updates for follow-me mode');
_positionSub = Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 1, // Update when moved at least 1 meter
),
).listen(
(Position position) {
final latLng = LatLng(position.latitude, position.longitude);
_currentLatLng = latLng;
if (!_hasLocation) {
debugPrint('[GpsController] GPS location acquired');
}
_hasLocation = true;
_cancelRetry(); // Got location, stop retrying
debugPrint('[GpsController] GPS position updated: ${latLng.latitude}, ${latLng.longitude} (accuracy: ${position.accuracy}m)');
},
onError: (error) {
debugPrint('[GpsController] Position stream error: $error');
if (_hasLocation) {
debugPrint('[GpsController] GPS location lost, starting retry attempts');
}
_hasLocation = false;
_currentLatLng = null;
_scheduleRetry(); // Lost location, start retrying
},
);
} else {
debugPrint('[GpsController] Starting standard-frequency GPS updates');
_positionSub = Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 5, // Update when moved at least 5 meters
),
).listen(
(Position position) {
final latLng = LatLng(position.latitude, position.longitude);
_currentLatLng = latLng;
if (!_hasLocation) {
debugPrint('[GpsController] GPS location acquired');
}
_hasLocation = true;
_cancelRetry(); // Got location, stop retrying
debugPrint('[GpsController] GPS position updated: ${latLng.latitude}, ${latLng.longitude} (accuracy: ${position.accuracy}m)');
},
onError: (error) {
debugPrint('[GpsController] Position stream error: $error');
if (_hasLocation) {
debugPrint('[GpsController] GPS location lost, starting retry attempts');
}
_hasLocation = false;
_currentLatLng = null;
_scheduleRetry(); // Lost location, start retrying
},
);
}
}
/// Dispose of GPS resources
void dispose() {
_positionSub?.cancel();
_positionSub = null;
_cancelRetry();
debugPrint('[GpsController] GPS controller disposed');
}
}

View File

@@ -44,6 +44,7 @@ class MapView extends StatefulWidget {
this.onSuspectedLocationTap,
this.onSearchPressed,
this.onNodeLimitChanged,
this.onLocationStatusChanged,
});
final FollowMeMode followMeMode;
@@ -54,6 +55,7 @@ class MapView extends StatefulWidget {
final void Function(SuspectedLocation)? onSuspectedLocationTap;
final VoidCallback? onSearchPressed;
final void Function(bool isLimited)? onNodeLimitChanged;
final VoidCallback? onLocationStatusChanged;
@override
State<MapView> createState() => MapViewState();
@@ -121,7 +123,10 @@ class MapViewState extends State<MapView> {
_gpsController.initializeWithCallback(
followMeMode: widget.followMeMode,
controller: _controller,
onLocationUpdated: () => setState(() {}),
onLocationUpdated: () {
setState(() {});
widget.onLocationStatusChanged?.call(); // Notify parent about location status change
},
getCurrentFollowMeMode: () {
// Use mounted check to avoid calling context when widget is disposed
if (mounted) {
@@ -230,6 +235,9 @@ class MapViewState extends State<MapView> {
LatLng? getUserLocation() {
return _gpsController.currentLocation;
}
/// Whether we currently have a valid GPS location
bool get hasLocation => _gpsController.hasLocation;
/// Expose static methods from MapPositionManager for external access
static Future<void> clearStoredMapPosition() =>

View File

@@ -0,0 +1,92 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import '../dev_config.dart';
import '../services/localization_service.dart';
/// Overlay that appears over add/edit node sheets to guide users through
/// the positioning tutorial. Shows a blurred background with tutorial text.
class PositioningTutorialOverlay extends StatelessWidget {
const PositioningTutorialOverlay({
super.key,
this.onFadeOutComplete,
});
/// Called when the fade-out animation completes (if animated)
final VoidCallback? onFadeOutComplete;
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: LocalizationService.instance,
builder: (context, child) {
final locService = LocalizationService.instance;
return ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: kPositioningTutorialBlurSigma,
sigmaY: kPositioningTutorialBlurSigma,
),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.3), // Semi-transparent overlay
),
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Tutorial icon
Icon(
Icons.pan_tool_outlined,
size: 48,
color: Colors.white,
),
const SizedBox(height: 16),
// Tutorial title
Text(
locService.t('positioningTutorial.title'),
style: const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
// Tutorial instructions
Text(
locService.t('positioningTutorial.instructions'),
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
// Additional hint
Text(
locService.t('positioningTutorial.hint'),
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 14,
fontStyle: FontStyle.italic,
),
textAlign: TextAlign.center,
),
],
),
),
),
),
),
);
},
);
}
}

View File

@@ -1,7 +1,7 @@
name: deflockapp
description: Map public surveillance infrastructure with OpenStreetMap
publish_to: "none"
version: 2.1.1+34 # The thing after the + is the version code, incremented with each release
version: 2.1.3+36 # The thing after the + is the version code, incremented with each release
environment:
sdk: ">=3.5.0 <4.0.0" # oauth2_client 4.x needs Dart 3.5+