diff --git a/analysis_options.yaml b/analysis_options.yaml index 0d29021..ce0711f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -21,8 +21,8 @@ linter: # `// ignore_for_file: name_of_lint` syntax on the line or in the file # producing the lint. rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options + avoid_print: true + prefer_final_fields: true + avoid_catches_without_on_clauses: true + curly_braces_in_flow_control_structures: true + control_flow_in_finally: true diff --git a/lib/config/runtime_config.dart b/lib/config/runtime_config.dart index b7d6c82..e48c140 100644 --- a/lib/config/runtime_config.dart +++ b/lib/config/runtime_config.dart @@ -21,13 +21,13 @@ class RuntimeConfig { static Future bootstrap() async { try { dotenv.env.clear(); - } catch (_) {} + } on Object catch (_) {} if (!kReleaseMode) { try { await dotenv.load(fileName: '.env'); appLog.i('Loaded local .env for development'); - } catch (_) {} + } on Object catch (_) {} } // ── Backend / cloud ──────────────────────────────────────────────────── diff --git a/lib/database/app_database.dart b/lib/database/app_database.dart index 952cc97..49b3c88 100644 --- a/lib/database/app_database.dart +++ b/lib/database/app_database.dart @@ -33,7 +33,7 @@ Future bootstrapSupabaseAuth() async { await ensureSupabaseAnonymousSession(Supabase.instance.client); _supabaseSdkInitialized = true; appLog.i('Supabase anonymous sign-in completed.'); - } catch (e, st) { + } on Object catch (e, st) { _supabaseSdkInitialized = false; appLog.e('Supabase bootstrap failed', error: e, stackTrace: st); } @@ -53,7 +53,7 @@ Future ensureSupabaseAnonymousSession(SupabaseClient client) async { if (after != null && !after.isExpired) { return; } - } catch (e, st) { + } on Object catch (e, st) { appLog.w( 'Session refresh failed; re-authenticating', error: e, @@ -62,7 +62,7 @@ Future ensureSupabaseAnonymousSession(SupabaseClient client) async { } } await client.auth.signInAnonymously(); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Anonymous auth failed', error: e, stackTrace: st); } } @@ -107,7 +107,7 @@ class SupabaseConnector extends PowerSyncBackendConnector { } } await transaction.complete(); - } catch (e, st) { + } on Object catch (e, st) { appLog.e('PowerSync upload error', error: e, stackTrace: st); } } @@ -163,7 +163,7 @@ Future initializeDatabase() async { appDb.connect(connector: SupabaseConnector(Supabase.instance.client)); _dbInitialized = true; appLog.i('PowerSync + Supabase initialized.'); - } catch (e, st) { + } on Object catch (e, st) { appLog.e('Database initialization failed', error: e, stackTrace: st); _dbInitialized = false; } diff --git a/lib/main.dart b/lib/main.dart index 6de2c7b..0382578 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -84,7 +84,7 @@ void main() async { // reads its configuration keys. try { await RuntimeConfig.bootstrap(); - } catch (e, st) { + } on Object catch (e, st) { // Non-fatal: all services check for missing config and degrade gracefully. appLog.w( '[boot] RuntimeConfig.bootstrap() failed — proceeding without config', @@ -158,7 +158,7 @@ class _RoadSOSAppState extends ConsumerState if (_servicesReady && accepted) { _runPostConsentHooks(); } - } catch (e, st) { + } on Object catch (e, st) { appLog.e('[boot] Privacy check failed', error: e, stackTrace: st); if (mounted) setState(() => _privacyReady = true); // unblock UI } @@ -191,7 +191,7 @@ class _RoadSOSAppState extends ConsumerState ); appLog.i('[boot] All services bootstrapped successfully.'); - } catch (e, st) { + } on Object catch (e, st) { // Non-fatal: app runs in offline/degraded mode. appLog.e( '[boot] Service bootstrap error — running in degraded mode', diff --git a/lib/services/agent_health_service.dart b/lib/services/agent_health_service.dart index be90ac3..ea1899e 100644 --- a/lib/services/agent_health_service.dart +++ b/lib/services/agent_health_service.dart @@ -190,7 +190,7 @@ class AgentHealthService { _gemmaCloudCached = result; _gemmaCloudCachedAt = DateTime.now(); return result; - } catch (e) { + } on Object catch (e) { appLog.d('[HealthCheck] Gemma cloud probe failed: $e'); _gemmaCloudCached = AgentReadiness.degraded; _gemmaCloudCachedAt = DateTime.now(); @@ -215,7 +215,7 @@ class AgentHealthService { return AgentReadiness.unavailable; } return AgentReadiness.ready; - } catch (_) { + } on Object catch (_) { return AgentReadiness.degraded; } } @@ -232,7 +232,7 @@ class AgentHealthService { // Fallback: open SMS app intent (no permission). If relay isn't configured, // we mark this as degraded (still usable, but requires user interaction). return AgentReadiness.degraded; - } catch (_) { + } on Object catch (_) { return AgentReadiness.degraded; } } @@ -241,7 +241,7 @@ class AgentHealthService { try { final status = await Permission.bluetooth.status; return status.isGranted ? AgentReadiness.ready : AgentReadiness.degraded; - } catch (_) { + } on Object catch (_) { return AgentReadiness.degraded; } } diff --git a/lib/services/ai_triage_service.dart b/lib/services/ai_triage_service.dart index 41515e4..6f7769c 100644 --- a/lib/services/ai_triage_service.dart +++ b/lib/services/ai_triage_service.dart @@ -232,7 +232,7 @@ class AiTriageService { ).timeout(cloudTimeout); appLog.i('[Triage] Tier 1 — Gemma 4 27B cloud ✓ (text-only auto-SOS)'); return cloud; - } catch (e, st) { + } on Object catch (e, st) { appLog.d( '[Triage] Tier 1 unavailable, trying Tier 2 on-device', error: e, @@ -253,7 +253,7 @@ class AiTriageService { appLog.i('[Triage] Tier 2 — Gemma 4 E4B on-device ✓'); return onDevice; } - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[Triage] Tier 2 on-device failed', error: e, stackTrace: st); } } @@ -313,7 +313,7 @@ class AiTriageService { '(${scenePhoto.sizeKb} KB · source=${cloud.source.name})', ); return cloud; - } catch (e, st) { + } on Object catch (e, st) { appLog.d( '[Triage] Vision cloud failed — falling back to text-only triage', error: e, diff --git a/lib/services/bluetooth_vehicle_monitor.dart b/lib/services/bluetooth_vehicle_monitor.dart index b47b3c4..6f78d49 100644 --- a/lib/services/bluetooth_vehicle_monitor.dart +++ b/lib/services/bluetooth_vehicle_monitor.dart @@ -80,14 +80,14 @@ class BluetoothVehicleMonitor { _lastSpeedKmh = (p.speed * 3.6).clamp(0.0, 320.0); } }, onError: (Object _) {}); - } catch (_) {} + } on Object catch (_) {} } void _poll() { List devices; try { devices = FlutterBluePlus.connectedDevices; - } catch (_) { + } on Object catch (_) { return; // BT not available on this device. } diff --git a/lib/services/bystander_coach_service.dart b/lib/services/bystander_coach_service.dart index 3bd9ef8..12c6a49 100644 --- a/lib/services/bystander_coach_service.dart +++ b/lib/services/bystander_coach_service.dart @@ -151,7 +151,7 @@ Response rules: _sttReady = await _stt.initialize( onError: (e) => appLog.w('[BystanderCoach] STT error: ${e.errorMsg}'), ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[BystanderCoach] STT init failed', error: e, stackTrace: st); _sttReady = false; } @@ -201,7 +201,7 @@ Response rules: Future _stopListeningSafely() async { try { if (_stt.isListening) await _stt.stop(); - } catch (_) {} + } on Object catch (_) {} } // ─── Core response loop ─────────────────────────────────────────────────── @@ -229,7 +229,7 @@ Response rules: try { await _ref.read(voiceAssistantServiceProvider).speak(reply); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[BystanderCoach] TTS speak failed', stackTrace: st); } state = state.copyWith(phase: BystanderCoachPhase.idle); @@ -353,7 +353,7 @@ Response rules: Future _firstAidGrounding(String query) async { try { return await FirstAidRepository.instance.lookup(query); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[BystanderCoach] first-aid lookup failed', stackTrace: st); return ''; } @@ -521,7 +521,7 @@ Response rules: if (gemma.isAvailable) { out = await gemma.generate(prompt).timeout(const Duration(seconds: 20)); } - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[BystanderCoach] gemma generate failed', stackTrace: st); } diff --git a/lib/services/camera_triage_service.dart b/lib/services/camera_triage_service.dart index eab4930..f0c2a5d 100644 --- a/lib/services/camera_triage_service.dart +++ b/lib/services/camera_triage_service.dart @@ -91,7 +91,7 @@ class CameraTriageService { sizeBytes: bytes.length, capturedAt: DateTime.now().toUtc(), ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[CameraTriageService] Image selection failed', error: e, @@ -132,7 +132,7 @@ class CameraTriageService { sizeBytes: bytes.length, capturedAt: DateTime.now().toUtc(), ); - } catch (e) { + } on Object catch (e) { appLog.d('[CameraTriageService] Silent capture failed: $e'); return null; } diff --git a/lib/services/crash_detection_service.dart b/lib/services/crash_detection_service.dart index 57d630d..d41f1ab 100644 --- a/lib/services/crash_detection_service.dart +++ b/lib/services/crash_detection_service.dart @@ -137,7 +137,7 @@ class CrashDetectionService { distanceFilter: 0, ), ).listen(_onPosition, onError: (Object _) => _gpsSpeedUsable = false); - } catch (_) { + } on Object catch (_) { _gpsSpeedUsable = false; } } diff --git a/lib/services/driving_mode_service.dart b/lib/services/driving_mode_service.dart index caa58df..1f83408 100644 --- a/lib/services/driving_mode_service.dart +++ b/lib/services/driving_mode_service.dart @@ -54,7 +54,7 @@ class DrivingModeService extends StateNotifier { distanceFilter: 20, ), ).listen(_onPosition, onError: (Object _) {}); - } catch (_) {} + } on Object catch (_) {} } void _onPosition(Position p) { diff --git a/lib/services/emergency_background_service.dart b/lib/services/emergency_background_service.dart index 097bd0a..f32a806 100644 --- a/lib/services/emergency_background_service.dart +++ b/lib/services/emergency_background_service.dart @@ -80,7 +80,7 @@ class EmergencyBackgroundService { ); _initialized = true; appLog.i('[BgService] Foreground service configured.'); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[BgService] Configure failed', error: e, stackTrace: st); } } @@ -159,7 +159,7 @@ class EmergencyBackgroundService { } else { appLog.d('[BgService] Battery optimization exemption already granted.'); } - } catch (e) { + } on Object catch (e) { appLog.w('[BgService] Battery exemption request failed: $e'); } } diff --git a/lib/services/emergency_beacon_service.dart b/lib/services/emergency_beacon_service.dart index 1877690..b71d4e1 100644 --- a/lib/services/emergency_beacon_service.dart +++ b/lib/services/emergency_beacon_service.dart @@ -48,11 +48,11 @@ class EmergencyBeaconService { try { await TorchLight.disableTorch(); - } catch (_) {} + } on Object catch (_) {} try { await _player.stop(); - } catch (_) {} + } on Object catch (_) {} appLog.i('✅ [BEACON] Hardware SOS signals disabled.'); } @@ -95,7 +95,7 @@ class EmergencyBeaconService { if (kIsWeb) return; try { await TorchLight.enableTorch(); - } catch (e) { + } on Object catch (e) { appLog.w('[BEACON] Failed to enable torch', error: e); } } @@ -104,7 +104,7 @@ class EmergencyBeaconService { if (kIsWeb) return; try { await TorchLight.disableTorch(); - } catch (e) { + } on Object catch (e) { appLog.w('[BEACON] Failed to disable torch', error: e); } } @@ -118,7 +118,7 @@ class EmergencyBeaconService { await _player.setLoopMode(LoopMode.one); await _player.setVolume(1.0); await _player.play(); - } catch (e) { + } on Object catch (e) { appLog.d('[BEACON] Siren failed to play: $e'); } } diff --git a/lib/services/emergency_notification_service.dart b/lib/services/emergency_notification_service.dart index da0d852..10ce2f4 100644 --- a/lib/services/emergency_notification_service.dart +++ b/lib/services/emergency_notification_service.dart @@ -75,7 +75,7 @@ class EmergencyNotificationService { ), ), ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Emergency local notification failed', error: e, stackTrace: st); } } @@ -84,6 +84,6 @@ class EmergencyNotificationService { if (kIsWeb) return; try { await _local.cancel(id: _sosActiveNotificationId); - } catch (_) {} + } on Object catch (_) {} } } diff --git a/lib/services/emergency_orchestrator.dart b/lib/services/emergency_orchestrator.dart index 1e8749f..d4bbb49 100644 --- a/lib/services/emergency_orchestrator.dart +++ b/lib/services/emergency_orchestrator.dart @@ -288,7 +288,7 @@ class EmergencyOrchestrator extends StateNotifier { .read(locationServiceProvider) .getCurrentLocation() .timeout(_sosLocationTimeout); - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[Orchestrator] Location acquisition timed out/failed', error: e, @@ -407,7 +407,7 @@ class EmergencyOrchestrator extends StateNotifier { scenePhoto: scenePhoto, ) .timeout(_sosTriageTimeout); - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[Orchestrator] Triage timed out/failed — using safety fallback', error: e, @@ -531,7 +531,7 @@ class EmergencyOrchestrator extends StateNotifier { return fallback; }, ); - } catch (_) { + } on Object catch (_) { _patchDispatchChannel( id, DispatchChannelLifecycle.failed, @@ -580,7 +580,7 @@ class EmergencyOrchestrator extends StateNotifier { triage: triage, ) .timeout(const Duration(seconds: 3)); - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[Orchestrator] structured SMS build failed — using legacy payload', error: e, @@ -708,7 +708,7 @@ class EmergencyOrchestrator extends StateNotifier { familyFuture, nearbyFuture, ]).timeout(_dispatchChannelTimeout + const Duration(seconds: 2)); - } catch (e, st) { + } on Object catch (e, st) { // Absolute guard: never hang in dispatching. appLog.w( '[Orchestrator] Dispatch futures did not complete in time', @@ -900,7 +900,7 @@ class EmergencyOrchestrator extends StateNotifier { ? 'Saved on device. Sync is enabled when network allows.' : 'Saved on device. Cloud sync needs Supabase credentials.', ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Local incident insert failed', error: e, stackTrace: st); return (ok: false, detail: 'Could not save incident log on device.'); } @@ -909,7 +909,7 @@ class EmergencyOrchestrator extends StateNotifier { bool _hasSupabaseSession() { try { return Supabase.instance.client.auth.currentSession != null; - } catch (_) { + } on Object catch (_) { return false; } } @@ -944,7 +944,7 @@ class EmergencyOrchestrator extends StateNotifier { } else { appLog.w('[Orchestrator] Could not launch dialer for $contact'); } - } catch (e, st) { + } on Object catch (e, st) { appLog.e( '[Orchestrator] Error launching dialer', error: e, @@ -968,7 +968,7 @@ class EmergencyOrchestrator extends StateNotifier { ? 'RoadSOS user' : profile.fullName.trim(), ); - } catch (e, st) { + } on Object catch (e, st) { appLog.d( '[Orchestrator] family circle SOS publish failed', stackTrace: st, @@ -983,7 +983,7 @@ class EmergencyOrchestrator extends StateNotifier { String? client; try { client = Supabase.instance.client.auth.currentUser?.id; - } catch (_) {} + } on Object catch (_) {} if (client == null) return; // Find the first member that is NOT the current user. final peer = circle.members.firstWhere( @@ -1001,7 +1001,7 @@ class EmergencyOrchestrator extends StateNotifier { if (res.error != null) { appLog.d('[Orchestrator] family ring skipped: ${res.error}'); } - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[Orchestrator] family ring failed', stackTrace: st); } } diff --git a/lib/services/emergency_sms_dispatch_service.dart b/lib/services/emergency_sms_dispatch_service.dart index be961fa..58586df 100644 --- a/lib/services/emergency_sms_dispatch_service.dart +++ b/lib/services/emergency_sms_dispatch_service.dart @@ -362,7 +362,7 @@ class EmergencySmsDispatchService { } else { appLog.w('India ERSS ingest HTTP ${response.statusCode}'); } - } catch (e, st) { + } on Object catch (e, st) { appLog.w('India ERSS ingest failed', error: e, stackTrace: st); } } @@ -378,7 +378,7 @@ class EmergencySmsDispatchService { .post(Uri.parse(url), headers: headers, body: jsonEncode(body)) .timeout(const Duration(seconds: 15)); return response.statusCode >= 200 && response.statusCode < 300; - } catch (e, st) { + } on Object catch (e, st) { appLog.w('SMS HTTP dispatch error', error: e, stackTrace: st); return false; } diff --git a/lib/services/family_circle_service.dart b/lib/services/family_circle_service.dart index 5359763..8ab87c7 100644 --- a/lib/services/family_circle_service.dart +++ b/lib/services/family_circle_service.dart @@ -180,7 +180,7 @@ class FamilyCircleService extends StateNotifier { try { return isSupabaseSdkInitialized && Supabase.instance.client.auth.currentSession != null; - } catch (_) { + } on Object catch (_) { return false; } } @@ -189,7 +189,7 @@ class FamilyCircleService extends StateNotifier { if (!isSupabaseSdkInitialized) return; try { await ensureSupabaseAnonymousSession(Supabase.instance.client); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[FamilyCircle] anon sign-in retry failed', stackTrace: st); } } @@ -273,7 +273,7 @@ class FamilyCircleService extends StateNotifier { ); await _resubscribePeerChannel(); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[FamilyCircle] refresh failed', error: e, stackTrace: st); state = state.copyWith(busy: false, lastError: 'Refresh failed: $e'); } @@ -283,7 +283,7 @@ class FamilyCircleService extends StateNotifier { if (!_hasSession) return; try { _peerChannel?.unsubscribe(); - } catch (_) {} + } on Object catch (_) {} _peerChannel = null; final client = Supabase.instance.client; @@ -307,7 +307,7 @@ class FamilyCircleService extends StateNotifier { row, ); state = state.copyWith(livePositions: updated); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[FamilyCircle] realtime decode failed', stackTrace: st); } }, @@ -336,7 +336,7 @@ class FamilyCircleService extends StateNotifier { }); await refresh(); return null; - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[FamilyCircle] createCircle failed', error: e, stackTrace: st); return 'Could not create circle: $e'; } @@ -364,7 +364,7 @@ class FamilyCircleService extends StateNotifier { }); final shareUrl = 'https://roadsos.app/i/$code'; return (code: code, shareUrl: shareUrl, error: null); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[FamilyCircle] createInvite failed', error: e, stackTrace: st); return (code: null, shareUrl: null, error: 'Invite create failed: $e'); } @@ -404,7 +404,7 @@ class FamilyCircleService extends StateNotifier { .eq('id', row['id']); await refresh(); return null; - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[FamilyCircle] redeemInvite failed', error: e, stackTrace: st); return 'Could not redeem invite: $e'; } @@ -491,7 +491,7 @@ class FamilyCircleService extends StateNotifier { .from('family_live_locations') .delete() .eq('user_id', client.auth.currentUser!.id); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[FamilyCircle] stopPublishing delete failed', stackTrace: st); } } @@ -526,7 +526,7 @@ class FamilyCircleService extends StateNotifier { 'destination': destination, 'updated_at': DateTime.now().toUtc().toIso8601String(), }); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[FamilyCircle] upsert failed', stackTrace: st); } } @@ -543,7 +543,7 @@ class FamilyCircleService extends StateNotifier { _positionSub?.cancel(); try { _peerChannel?.unsubscribe(); - } catch (_) {} + } on Object catch (_) {} super.dispose(); } } diff --git a/lib/services/family_tracking_service.dart b/lib/services/family_tracking_service.dart index 4f55cb2..1c53541 100644 --- a/lib/services/family_tracking_service.dart +++ b/lib/services/family_tracking_service.dart @@ -87,7 +87,7 @@ class FamilyTrackingService { 'expires_at': expiresAt.toIso8601String(), 'updated_at': DateTime.now().toUtc().toIso8601String(), }); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('incident_live_links insert failed', error: e, stackTrace: st); return ( ok: false, diff --git a/lib/services/first_aid_repository.dart b/lib/services/first_aid_repository.dart index ae9d3da..4204aa8 100644 --- a/lib/services/first_aid_repository.dart +++ b/lib/services/first_aid_repository.dart @@ -190,7 +190,7 @@ CREATE VIRTUAL TABLE IF NOT EXISTS first_aid_fts USING fts5( return (data['text'] as String).trim(); } return null; - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[FirstAid] Gemma 4 compose failed', error: e, stackTrace: st); return null; } @@ -257,7 +257,7 @@ CREATE VIRTUAL TABLE IF NOT EXISTS first_aid_fts USING fts5( ''', [ftsQuery], ); - } catch (e) { + } on Object { rows = []; } @@ -272,7 +272,7 @@ CREATE VIRTUAL TABLE IF NOT EXISTS first_aid_fts USING fts5( ''', ['general OR trauma OR emergency OR india OR 108'], ); - } catch (e) { + } on Object { rows = []; } } diff --git a/lib/services/gemma_auto_downloader.dart b/lib/services/gemma_auto_downloader.dart index 2fb0ddc..15ca852 100644 --- a/lib/services/gemma_auto_downloader.dart +++ b/lib/services/gemma_auto_downloader.dart @@ -107,7 +107,7 @@ class GemmaAutoDownloader extends StateNotifier { unawaited(_kick()); } }); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[GemmaAuto] bootstrap failed', error: e, stackTrace: st); state = state.copyWith( state: GemmaAutoState.failed, @@ -193,7 +193,7 @@ class GemmaAutoDownloader extends StateNotifier { state: GemmaAutoState.failed, errorMessage: e.message, ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[GemmaAuto] download failed', error: e, stackTrace: st); state = state.copyWith( state: GemmaAutoState.failed, diff --git a/lib/services/gemma_local_service.dart b/lib/services/gemma_local_service.dart index 0519af7..97ad0e4 100644 --- a/lib/services/gemma_local_service.dart +++ b/lib/services/gemma_local_service.dart @@ -62,7 +62,7 @@ class GemmaLocalService { ' Model not downloaded yet? Run model download during onboarding.', ); } - } catch (e, st) { + } on Object catch (e, st) { _lastError = 'Init error: $e'; _available = false; appLog.w('[GemmaLocal] Init failed', error: e, stackTrace: st); @@ -117,7 +117,7 @@ class GemmaLocalService { appLog.d( '[GemmaLocal] loadModel() not in this build — will pass via init()', ); - } catch (e) { + } on Object catch (e) { appLog.w('[GemmaLocal] loadModel() threw: $e — trying init() fallback'); } @@ -153,7 +153,7 @@ class GemmaLocalService { ); } } - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[GemmaLocal] flutter_gemma init() failed', error: e, @@ -195,7 +195,7 @@ class GemmaLocalService { ); } return parsed; - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[GemmaLocal] Inference failed — marking tier unavailable', error: e, @@ -213,7 +213,7 @@ class GemmaLocalService { try { final result = await _plugin!.getResponse(prompt: prompt); return result; - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[GemmaLocal] generate() failed', error: e, stackTrace: st); _available = false; return null; @@ -227,7 +227,7 @@ class GemmaLocalService { await for (final token in _plugin!.getResponseAsync(prompt: prompt)) { if (token != null) yield token; } - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[GemmaLocal] generateStream() failed', error: e, @@ -267,7 +267,7 @@ class GemmaLocalService { if (s < 0 || e <= s) return null; final decoded = jsonDecode(text.substring(s, e + 1)); return decoded is Map ? decoded : null; - } catch (_) { + } on Object catch (_) { return null; } } diff --git a/lib/services/gemma_model_manager.dart b/lib/services/gemma_model_manager.dart index 0fde426..c08b4d6 100644 --- a/lib/services/gemma_model_manager.dart +++ b/lib/services/gemma_model_manager.dart @@ -78,7 +78,7 @@ class GemmaModelManager { final file = File(await localModelPath()); if (!file.existsSync()) return false; return file.lengthSync() >= expectedMinBytes; - } catch (_) { + } on Object catch (_) { return false; } } @@ -88,7 +88,7 @@ class GemmaModelManager { try { final file = File(await localModelPath()); return file.existsSync() ? file.lengthSync() : 0; - } catch (_) { + } on Object catch (_) { return 0; } } @@ -98,7 +98,7 @@ class GemmaModelManager { try { final tmp = File('${await localModelPath()}.download'); return tmp.existsSync() ? tmp.lengthSync() : 0; - } catch (_) { + } on Object catch (_) { return 0; } } diff --git a/lib/services/gyroscope_fusion_service.dart b/lib/services/gyroscope_fusion_service.dart index ae7b971..ced8b4c 100644 --- a/lib/services/gyroscope_fusion_service.dart +++ b/lib/services/gyroscope_fusion_service.dart @@ -40,7 +40,7 @@ class GyroscopeFusionService { ); _available = true; appLog.d('[Gyro] Gyroscope fusion tracking started'); - } catch (e) { + } on Object catch (e) { _available = false; appLog.d('[Gyro] Gyroscope unavailable on this device: $e'); } diff --git a/lib/services/india_offline_dispatch.dart b/lib/services/india_offline_dispatch.dart index 3209675..2224a3e 100644 --- a/lib/services/india_offline_dispatch.dart +++ b/lib/services/india_offline_dispatch.dart @@ -54,7 +54,7 @@ class IndiaOfflineDispatch { await launchUrl(uri, mode: LaunchMode.externalApplication); appLog.d('India: launched $desc'); } - } catch (e, st) { + } on Object catch (e, st) { appLog.w('India: could not launch $desc', error: e, stackTrace: st); } } @@ -66,7 +66,7 @@ class IndiaOfflineDispatch { await launchUrl(uri, mode: LaunchMode.externalApplication); appLog.d('India USSD intent: $code'); } - } catch (e, st) { + } on Object catch (e, st) { appLog.w('India USSD launch failed', error: e, stackTrace: st); } } diff --git a/lib/services/ios_lifecycle_service.dart b/lib/services/ios_lifecycle_service.dart index 415c33a..0e566e7 100644 --- a/lib/services/ios_lifecycle_service.dart +++ b/lib/services/ios_lifecycle_service.dart @@ -46,7 +46,7 @@ class IosLifecycleService { if (!Platform.isIOS) return; try { await _channel.invokeMethod('scheduleBackgroundRefresh'); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('scheduleBackgroundRefresh failed', error: e, stackTrace: st); } } diff --git a/lib/services/location_service.dart b/lib/services/location_service.dart index 04f58fe..6287f70 100644 --- a/lib/services/location_service.dart +++ b/lib/services/location_service.dart @@ -82,7 +82,7 @@ class LocationService { '[Location] GPS fix acquired (attempt 1): ${fix.accuracy.round()}m', ); return fix; - } catch (e) { + } on Object catch (e) { appLog.d( '[Location] Attempt 1 failed ($e) — retrying at medium accuracy', ); @@ -103,7 +103,7 @@ class LocationService { '[Location] GPS fix acquired (attempt 2 medium): ${fix.accuracy.round()}m', ); return fix; - } catch (e) { + } on Object catch (e) { appLog.d('[Location] Attempt 2 failed ($e) — trying last known from OS'); } @@ -118,7 +118,7 @@ class LocationService { ); return fix; } - } catch (_) {} + } on Object catch (_) {} return _fallbackLocation('All location attempts failed'); } diff --git a/lib/services/map_tile_cache.dart b/lib/services/map_tile_cache.dart index 56d2be0..388a826 100644 --- a/lib/services/map_tile_cache.dart +++ b/lib/services/map_tile_cache.dart @@ -15,7 +15,7 @@ Future initializeFmtcMapCache() async { await FMTCObjectBoxBackend().initialise(); await FMTCStore(kFmtcRoadsosOsmStore).manage.create(); fmtcMapCacheReady = true; - } catch (e, st) { + } on Object catch (e, st) { fmtcMapCacheReady = false; appLog.w( 'FMTC map cache init failed — using network tiles only', diff --git a/lib/services/mesh_network_service.dart b/lib/services/mesh_network_service.dart index b5df214..a2680d9 100644 --- a/lib/services/mesh_network_service.dart +++ b/lib/services/mesh_network_service.dart @@ -77,7 +77,7 @@ class MeshNetworkService { if (Platform.isAndroid || Platform.isIOS) { try { unawaited(FlutterBluePlus.stopScan()); - } catch (_) {} + } on Object catch (_) {} } } } @@ -137,7 +137,7 @@ class MeshNetworkService { if (!Platform.isAndroid && !Platform.isIOS) return; try { await FlutterBluePlus.startScan(timeout: const Duration(seconds: 30)); - } catch (e) { + } on Object catch (e) { appLog.w('Failed to start BLE scan', error: e); } } @@ -145,7 +145,7 @@ class MeshNetworkService { String? _tryDecodeUtf8(List data) { try { return utf8.decode(data, allowMalformed: true).trim(); - } catch (_) { + } on Object catch (_) { return null; } } @@ -232,7 +232,7 @@ class MeshNetworkService { await _peripheral.start(advertiseData: advertiseData); appLog.d('BLE mesh advertising SOS (${advertiseBytes.length}B)'); return true; - } catch (e, st) { + } on Object catch (e, st) { appLog.w('BLE advertising failed', error: e, stackTrace: st); return false; } @@ -292,7 +292,7 @@ final meshListeningBootstrapProvider = FutureProvider((ref) async { final mesh = ref.watch(meshNetworkServiceProvider); try { await mesh.ensureListeningForPeers(); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Mesh listening bootstrap failed', error: e, stackTrace: st); } }); diff --git a/lib/services/multi_agent_coordinator.dart b/lib/services/multi_agent_coordinator.dart index 8499e3d..fe62fe1 100644 --- a/lib/services/multi_agent_coordinator.dart +++ b/lib/services/multi_agent_coordinator.dart @@ -86,7 +86,7 @@ class MultiAgentCoordinator { final result = await work(); _transition(task, AgentStatus.completed); return result; - } catch (e, st) { + } on Object catch (e, st) { _transition(task, AgentStatus.failed, error: e.toString()); appLog.w('[Agent] ${task.displayName} failed', error: e, stackTrace: st); return null; diff --git a/lib/services/nearby_services_broadcast_service.dart b/lib/services/nearby_services_broadcast_service.dart index 9c730b7..54a1aaf 100644 --- a/lib/services/nearby_services_broadcast_service.dart +++ b/lib/services/nearby_services_broadcast_service.dart @@ -79,7 +79,7 @@ class NearbyServicesBroadcastService { SupabaseClient client; try { client = Supabase.instance.client; - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[NearbyBroadcast] Supabase not initialised', error: e, @@ -165,7 +165,7 @@ class NearbyServicesBroadcastService { ok: false, detail: 'Failed — realtime send timed out (>3s).', ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[NearbyBroadcast] Broadcast failed', error: e, stackTrace: st); return NearbyBroadcastOutcome( ok: false, @@ -176,7 +176,7 @@ class NearbyServicesBroadcastService { if (channel != null) { try { await client.removeChannel(channel); - } catch (_) { + } on Object catch (_) { /* best-effort */ } } diff --git a/lib/services/nearby_sos_push_service.dart b/lib/services/nearby_sos_push_service.dart index 0c4dce9..2a518f3 100644 --- a/lib/services/nearby_sos_push_service.dart +++ b/lib/services/nearby_sos_push_service.dart @@ -40,7 +40,7 @@ class NearbySosPushService { if (Firebase.apps.isEmpty) { await Firebase.initializeApp(); } - } catch (e, st) { + } on Object catch (e, st) { appLog.w( 'Firebase not configured (add google-services.json / FirebaseOptions). Nearby SOS push disabled.', error: e, @@ -88,7 +88,7 @@ class NearbySosPushService { } else { await messaging.unsubscribeFromTopic(_topic); } - } catch (e, st) { + } on Object catch (e, st) { appLog.w( 'FCM topic subscribe/unsubscribe failed', error: e, @@ -184,7 +184,7 @@ class NearbySosPushService { if (!enabled) { try { await FirebaseMessaging.instance.unsubscribeFromTopic(_topic); - } catch (_) {} + } on Object catch (_) {} } return true; } diff --git a/lib/services/predictive_sos_preloader.dart b/lib/services/predictive_sos_preloader.dart index ff856dd..2b5d096 100644 --- a/lib/services/predictive_sos_preloader.dart +++ b/lib/services/predictive_sos_preloader.dart @@ -48,7 +48,7 @@ class PredictiveSosPreloader { .head(Uri.parse('$url/functions/v1/triage-gemini')) .timeout(const Duration(seconds: 4)); appLog.d('[Preloader] Supabase edge TLS session pre-warmed ✓'); - } catch (_) { + } on Object catch (_) { // Expected on first cold-start or offline — not an error. appLog.d('[Preloader] Supabase pre-warm skipped (offline or timeout)'); } @@ -77,7 +77,7 @@ class PredictiveSosPreloader { ), ); appLog.d('[Preloader] GPS chipset pre-warmed ✓'); - } catch (_) { + } on Object catch (_) { appLog.d('[Preloader] GPS pre-warm skipped'); } } diff --git a/lib/services/privacy_consent_service.dart b/lib/services/privacy_consent_service.dart index 7ec79ba..315c364 100644 --- a/lib/services/privacy_consent_service.dart +++ b/lib/services/privacy_consent_service.dart @@ -35,7 +35,7 @@ class PrivacyConsentService { static Future extendedRetentionForUploads() async { try { return await extendedCloudRetentionEnabled(); - } catch (_) { + } on Object catch (_) { return false; } } diff --git a/lib/services/remote_crash_config.dart b/lib/services/remote_crash_config.dart index 23bffa3..32420f4 100644 --- a/lib/services/remote_crash_config.dart +++ b/lib/services/remote_crash_config.dart @@ -313,7 +313,7 @@ class RemoteCrashConfig { '[RemoteCrashConfig] Thresholds refreshed: ' '${rows.length} rows, zones=${_values.keys.toList()}', ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[RemoteCrashConfig] Threshold fetch failed — cached values in use', error: e, @@ -345,7 +345,7 @@ class RemoteCrashConfig { priority: (row['priority'] as num).toInt(), ), ); - } catch (_) {} + } on Object catch (_) {} } _regions @@ -356,7 +356,7 @@ class RemoteCrashConfig { appLog.i( '[RemoteCrashConfig] Regions refreshed: ${_regions.length} geofences', ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w( '[RemoteCrashConfig] Region fetch failed — cached regions in use', error: e, @@ -380,7 +380,7 @@ class RemoteCrashConfig { (k, v) => MapEntry(k, (v as num).toDouble()), ); } - } catch (e) { + } on Object catch (e) { appLog.d('[RemoteCrashConfig] Threshold cache empty (first run): $e'); } } @@ -389,7 +389,7 @@ class RemoteCrashConfig { try { final prefs = await SharedPreferences.getInstance(); await prefs.setString(_cacheKey, jsonEncode(_values)); - } catch (e) { + } on Object catch (e) { appLog.d('[RemoteCrashConfig] Threshold cache write failed: $e'); } } @@ -415,7 +415,7 @@ class RemoteCrashConfig { ), ); } - } catch (e) { + } on Object catch (e) { appLog.d('[RemoteCrashConfig] Region cache empty (first run): $e'); } } @@ -437,7 +437,7 @@ class RemoteCrashConfig { ) .toList(); await prefs.setString(_regionsCacheKey, jsonEncode(list)); - } catch (e) { + } on Object catch (e) { appLog.d('[RemoteCrashConfig] Region cache write failed: $e'); } } diff --git a/lib/services/roadsos_assistant_service.dart b/lib/services/roadsos_assistant_service.dart index c083aba..0c9c9a5 100644 --- a/lib/services/roadsos_assistant_service.dart +++ b/lib/services/roadsos_assistant_service.dart @@ -180,7 +180,7 @@ class RoadSosAssistantService extends StateNotifier { return (data['text'] as String).trim(); } return null; - } catch (e, st) { + } on Object catch (e, st) { appLog.d( '[Assistant] Gemma 4 cloud generate failed', error: e, @@ -249,7 +249,7 @@ class RoadSosAssistantService extends StateNotifier { } } return _detectSceneContextLocal(input); - } catch (_) { + } on Object catch (_) { return _detectSceneContextLocal(input); } } @@ -295,7 +295,7 @@ class RoadSosAssistantService extends StateNotifier { ); if (line.length > 240) line = '${line.substring(0, 240)}…'; return line.isEmpty ? null : line; - } catch (_) { + } on Object catch (_) { return null; } } diff --git a/lib/services/safe_walk_navigator_service.dart b/lib/services/safe_walk_navigator_service.dart index e2733e4..5d0c61d 100644 --- a/lib/services/safe_walk_navigator_service.dart +++ b/lib/services/safe_walk_navigator_service.dart @@ -228,11 +228,11 @@ class SafeWalkNavigatorService extends StateNotifier { ), ); return LatLng(pos.latitude, pos.longitude); - } catch (_) { + } on Object catch (_) { try { final pos = await Geolocator.getLastKnownPosition(); if (pos != null) return LatLng(pos.latitude, pos.longitude); - } catch (_) {} + } on Object catch (_) {} return null; } } @@ -289,7 +289,7 @@ class SafeWalkNavigatorService extends StateNotifier { currentStepIndex: 0, routingDegraded: false, ); - } catch (e, st) { + } on Object catch (e, st) { appLog.d( '[SafeWalkNav] OSRM unreachable, falling back to bearing-only', stackTrace: st, diff --git a/lib/services/safe_walk_notification_service.dart b/lib/services/safe_walk_notification_service.dart index de2cd6e..6dc6d7a 100644 --- a/lib/services/safe_walk_notification_service.dart +++ b/lib/services/safe_walk_notification_service.dart @@ -105,7 +105,7 @@ class SafeWalkNotificationService { iOS: DarwinNotificationDetails(), ), ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Safe Walk local notification failed', error: e, stackTrace: st); } } @@ -113,7 +113,7 @@ class SafeWalkNotificationService { Future cancelCheckInNotification() async { try { await _local.cancel(id: _checkInNotificationId); - } catch (_) {} + } on Object catch (_) {} } /// Best-effort foreground prompt for users already in-app. diff --git a/lib/services/scene_security_service.dart b/lib/services/scene_security_service.dart index 6d965d9..d849cb4 100644 --- a/lib/services/scene_security_service.dart +++ b/lib/services/scene_security_service.dart @@ -63,7 +63,7 @@ class SceneSecurityService { final clear = await _aead.decrypt(secretBox, secretKey: secretKey); return utf8.decode(clear); - } catch (_) { + } on Object catch (_) { return null; } } diff --git a/lib/services/sms_direct_send_io.dart b/lib/services/sms_direct_send_io.dart index 522644b..c5186be 100644 --- a/lib/services/sms_direct_send_io.dart +++ b/lib/services/sms_direct_send_io.dart @@ -43,7 +43,7 @@ Future sendSmsDirectAndroidImpl(String number, String message) async { appLog.w('[SmsDirect] launchUrl returned false for SMS URI'); } return launched; - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[SmsDirect] SMS launch failed', error: e, stackTrace: st); return false; } diff --git a/lib/services/sms_permission_bootstrap_io.dart b/lib/services/sms_permission_bootstrap_io.dart index cca310f..5f46d17 100644 --- a/lib/services/sms_permission_bootstrap_io.dart +++ b/lib/services/sms_permission_bootstrap_io.dart @@ -17,7 +17,7 @@ Future requestSmsPermissionEarlyIfAndroidImpl() async { await Permission .sms .status; // keep plugin warmed for health checks if needed - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Startup SMS permission request failed', error: e, stackTrace: st); } } diff --git a/lib/services/sos_activity_log_service.dart b/lib/services/sos_activity_log_service.dart index c68208e..f66e6b7 100644 --- a/lib/services/sos_activity_log_service.dart +++ b/lib/services/sos_activity_log_service.dart @@ -23,7 +23,7 @@ class SosActivityLogService { return list .map((e) => SosActivityRecord.fromJson(e as Map)) .toList(); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Activity log parse failed', error: e, stackTrace: st); return []; } @@ -40,7 +40,7 @@ class SosActivityLogService { key: _key, value: jsonEncode(trimmed.map((e) => e.toJson()).toList()), ); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Activity log append failed', error: e, stackTrace: st); } } diff --git a/lib/services/sos_location_tracker.dart b/lib/services/sos_location_tracker.dart index 01bab90..fb81452 100644 --- a/lib/services/sos_location_tracker.dart +++ b/lib/services/sos_location_tracker.dart @@ -123,7 +123,7 @@ class SosLocationTracker { SupabaseClient client; try { client = Supabase.instance.client; - } catch (_) { + } on Object catch (_) { return; } @@ -144,7 +144,7 @@ class SosLocationTracker { '${pos.latitude.toStringAsFixed(4)}, ${pos.longitude.toStringAsFixed(4)} ' 'acc=${pos.accuracy.toStringAsFixed(0)}m', ); - } catch (e) { + } on Object catch (e) { appLog.w( '[SosLocationTracker] Update failed: $e — will retry next cycle', ); diff --git a/lib/services/structured_sms_service.dart b/lib/services/structured_sms_service.dart index c4d96a7..3ea2c3f 100644 --- a/lib/services/structured_sms_service.dart +++ b/lib/services/structured_sms_service.dart @@ -172,7 +172,7 @@ class StructuredSmsService { 'O${v.bloodOxygen.round()}', ]; return parts.join(','); - } catch (_) { + } on Object catch (_) { return 'C?B?Bl?'; } } @@ -231,7 +231,7 @@ class StructuredSmsService { .firstWhere((l) => l.contains('RSOS|'), orElse: () => ''); if (line.isEmpty) return null; return line.trim(); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[StructuredSMS] gemma compose skipped: $e', stackTrace: st); return null; } diff --git a/lib/services/wake_lock_service.dart b/lib/services/wake_lock_service.dart index 71028c2..0c28c1c 100644 --- a/lib/services/wake_lock_service.dart +++ b/lib/services/wake_lock_service.dart @@ -28,7 +28,7 @@ class WakeLockService { await WakelockPlus.enable(); _held = true; appLog.i('[WakeLock] Screen wake lock acquired for active SOS'); - } catch (e) { + } on Object catch (e) { appLog.w('[WakeLock] Failed to acquire: $e'); } } @@ -40,7 +40,7 @@ class WakeLockService { await WakelockPlus.disable(); _held = false; appLog.d('[WakeLock] Screen wake lock released'); - } catch (e) { + } on Object catch (e) { appLog.w('[WakeLock] Failed to release: $e'); } } diff --git a/lib/services/webrtc_voice_call_service.dart b/lib/services/webrtc_voice_call_service.dart index 588495d..573d39f 100644 --- a/lib/services/webrtc_voice_call_service.dart +++ b/lib/services/webrtc_voice_call_service.dart @@ -123,7 +123,7 @@ class WebRtcVoiceCallService extends StateNotifier { try { return isSupabaseSdkInitialized && Supabase.instance.client.auth.currentSession != null; - } catch (_) { + } on Object catch (_) { return false; } } @@ -137,7 +137,7 @@ class WebRtcVoiceCallService extends StateNotifier { Future _subscribeToIncomingCalls() async { try { _ringChannel?.unsubscribe(); - } catch (_) {} + } on Object catch (_) {} final client = Supabase.instance.client; final uid = client.auth.currentUser!.id; @@ -169,7 +169,7 @@ class WebRtcVoiceCallService extends StateNotifier { startedAt: DateTime.now(), ); unawaited(_ringPulse()); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[WebRTC] ring decode failed', error: e, stackTrace: st); } }, @@ -235,7 +235,7 @@ class WebRtcVoiceCallService extends StateNotifier { }); return (ok: true, error: null); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[WebRTC] startCall failed', error: e, stackTrace: st); await _teardown(); state = state.copyWith( @@ -297,7 +297,7 @@ class WebRtcVoiceCallService extends StateNotifier { 'answered_at': DateTime.now().toUtc().toIso8601String(), }) .eq('id', callId); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('[WebRTC] answer failed', error: e, stackTrace: st); await _teardown(); state = state.copyWith( @@ -314,7 +314,7 @@ class WebRtcVoiceCallService extends StateNotifier { if (callId != null && peerId != null) { try { await _sendSignal(callId, peerId, 'bye', {'reason': reason}); - } catch (_) {} + } on Object catch (_) {} await _markCall(callId, reason); } await _teardown(); @@ -333,7 +333,7 @@ class WebRtcVoiceCallService extends StateNotifier { try { await Helper.setSpeakerphoneOn(on); state = state.copyWith(speakerOn: on); - } catch (e) { + } on Object catch (e) { appLog.d('[WebRTC] speaker toggle failed: $e'); } } @@ -384,7 +384,7 @@ class WebRtcVoiceCallService extends StateNotifier { Future _subscribeToSignals(String callId) async { try { _signalChannel?.unsubscribe(); - } catch (_) {} + } on Object catch (_) {} final client = Supabase.instance.client; _signalChannel = client .channel('public:voice_call_signals:call-$callId') @@ -403,7 +403,7 @@ class WebRtcVoiceCallService extends StateNotifier { ? jsonDecode(row['payload'] as String) as Map : (row['payload'] as Map).cast(); await _handleIncomingSignal(kind, pl); - } catch (e, st) { + } on Object catch (e, st) { appLog.d('[WebRTC] signal decode failed', stackTrace: st); } }, @@ -450,7 +450,7 @@ class WebRtcVoiceCallService extends StateNotifier { while (_pendingRemoteIce.isNotEmpty) { try { await _pc!.addCandidate(_pendingRemoteIce.removeAt(0)); - } catch (e) { + } on Object catch (e) { appLog.d('[WebRTC] addCandidate pending failed: $e'); } } @@ -484,7 +484,7 @@ class WebRtcVoiceCallService extends StateNotifier { 'ended_by': client.auth.currentUser!.id, }) .eq('id', callId); - } catch (e) { + } on Object catch (e) { appLog.d('[WebRTC] _markCall failed: $e'); } } @@ -494,19 +494,19 @@ class WebRtcVoiceCallService extends StateNotifier { _outgoingTimeout = null; try { await _pc?.close(); - } catch (_) {} + } on Object catch (_) {} _pc = null; try { for (final track in (_localStream?.getTracks() ?? [])) { await track.stop(); } await _localStream?.dispose(); - } catch (_) {} + } on Object catch (_) {} _localStream = null; _pendingRemoteIce.clear(); try { _signalChannel?.unsubscribe(); - } catch (_) {} + } on Object catch (_) {} _signalChannel = null; } @@ -519,7 +519,7 @@ class WebRtcVoiceCallService extends StateNotifier { await HapticFeedback.heavyImpact(); await Future.delayed(const Duration(milliseconds: 180)); await HapticFeedback.lightImpact(); - } catch (_) {} + } on Object catch (_) {} await Future.delayed(const Duration(milliseconds: 900)); } } @@ -529,7 +529,7 @@ class WebRtcVoiceCallService extends StateNotifier { unawaited(_teardown()); try { _ringChannel?.unsubscribe(); - } catch (_) {} + } on Object catch (_) {} super.dispose(); } } diff --git a/lib/ui/bystander_radar.dart b/lib/ui/bystander_radar.dart index eb8e0c6..18b3656 100644 --- a/lib/ui/bystander_radar.dart +++ b/lib/ui/bystander_radar.dart @@ -96,7 +96,7 @@ class _BystanderRadarState extends ConsumerState if (!mounted) return; setState(() => _myFix = p); }); - } catch (_) { + } on Object catch (_) { /* permission or platform — radar still renders dots */ } } diff --git a/lib/ui/dashboard.dart b/lib/ui/dashboard.dart index ebc64c1..9afe9f7 100644 --- a/lib/ui/dashboard.dart +++ b/lib/ui/dashboard.dart @@ -986,7 +986,7 @@ class _DashboardScreenState extends ConsumerState ), ); } - } catch (e) { + } on Object catch (e) { appLog.w('Error fetching location suggestions: $e'); } return const Iterable<_NominatimHit>.empty(); diff --git a/lib/ui/first_aid_screen.dart b/lib/ui/first_aid_screen.dart index fa2f19a..a0c08e4 100644 --- a/lib/ui/first_aid_screen.dart +++ b/lib/ui/first_aid_screen.dart @@ -76,7 +76,7 @@ class _FirstAidScreenState extends ConsumerState { // Side-channel: keep FirstAidStore primed (used elsewhere) — best-effort. // ignore: discarded_futures FirstAidStore.getVerifiedAdvice(query); - } catch (e) { + } on Object { setState(() { _error = 'Could not load first-aid guidance on this device.'; }); diff --git a/lib/ui/gemma_model_download_screen.dart b/lib/ui/gemma_model_download_screen.dart index 8e3f141..fb6876e 100644 --- a/lib/ui/gemma_model_download_screen.dart +++ b/lib/ui/gemma_model_download_screen.dart @@ -103,7 +103,7 @@ class _GemmaModelDownloadScreenState extends State { _phase = _Phase.prompt; _errorMessage = e.message; }); - } catch (e) { + } on Object catch (e) { if (!mounted) return; setState(() { _phase = _Phase.prompt; diff --git a/lib/ui/incident_reporting_screen.dart b/lib/ui/incident_reporting_screen.dart index 04b6852..344cec3 100644 --- a/lib/ui/incident_reporting_screen.dart +++ b/lib/ui/incident_reporting_screen.dart @@ -168,7 +168,7 @@ class _IncidentReportingScreenState maxWidth: 1600, ); if (file != null) bytes = await file.readAsBytes(); - } catch (_) { + } on Object catch (_) { // On emulators / devices without camera, silently fall back to gallery. } @@ -180,7 +180,7 @@ class _IncidentReportingScreenState maxWidth: 1600, ); if (file != null) bytes = await file.readAsBytes(); - } catch (e) { + } on Object { if (!mounted) return; setState(() => _sceneCaptureBusy = false); ScaffoldMessenger.of(context).showSnackBar( diff --git a/lib/ui/offline_map_screen.dart b/lib/ui/offline_map_screen.dart index adb8ce6..1508236 100644 --- a/lib/ui/offline_map_screen.dart +++ b/lib/ui/offline_map_screen.dart @@ -142,7 +142,7 @@ class _OfflineMapScreenState extends ConsumerState { ); // No await on completion: download runs in foreground thread; UI updates via stream. - } catch (e, st) { + } on Object catch (e, st) { appLog.w('Offline map download failed', error: e, stackTrace: st); if (!mounted) return; setState(() { @@ -156,7 +156,7 @@ class _OfflineMapScreenState extends ConsumerState { Future _cancelDownload() async { try { await FMTCStore(kFmtcRoadsosOsmStore).download.cancel(); - } catch (e, st) { + } on Object catch (e, st) { appLog.w('FMTC download cancel failed', error: e, stackTrace: st); } if (!mounted) return; diff --git a/lib/ui/privacy_policy_screen.dart b/lib/ui/privacy_policy_screen.dart index 795b637..01a5e01 100644 --- a/lib/ui/privacy_policy_screen.dart +++ b/lib/ui/privacy_policy_screen.dart @@ -36,7 +36,7 @@ class _PrivacyPolicyScreenState extends State { _hi = hi; }); } - } catch (_) { + } on Object catch (_) { if (mounted) { setState(() { _en = 'Privacy text asset missing.'; diff --git a/lib/ui/safe_walk_navigator_screen.dart b/lib/ui/safe_walk_navigator_screen.dart index 53e198f..205937b 100644 --- a/lib/ui/safe_walk_navigator_screen.dart +++ b/lib/ui/safe_walk_navigator_screen.dart @@ -94,7 +94,7 @@ class _SafeWalkNavigatorScreenState Future _speak(String text) async { try { await ref.read(voiceAssistantServiceProvider).speak(text); - } catch (_) {} + } on Object catch (_) {} } @override @@ -124,7 +124,7 @@ class _SafeWalkNavigatorScreenState // Re-center the map gently on the user. try { _mapController.move(mePoint, _mapController.camera.zoom); - } catch (_) {} + } on Object catch (_) {} } return Scaffold(