3 KiB
3 KiB
Agents — Traccar Client
Verify before claiming
- Run
flutter analyzebefore every commit — this project had 22 deprecated API violations (.withOpacity()→.withValues(alpha:),value→initialValueonDropdownButtonFormField,activeColor→activeThumbColoronSwitch) - Always run
flutter build apk --debugto confirm the APK builds after any Dart or Kotlin change
Commands
flutter analyze # lint + typecheck (run before commit)
flutter build apk --debug # build Android APK
dart format . # format all Dart files
Architecture
- Flutter Android app with a MethodChannel (
com.traccar.client/tracking) bridging to native Kotlin services - 4 screens:
PermissionScreen→MainScreen→SettingsScreen/StatusScreen - LocationBridge (
lib/bridge/location_bridge.dart) — the only Dart→Native bridge; all tracking starts here - Native: Kotlin services in
android/app/src/main/kotlin/com/traccar/traccar_client/BridgeModule.kt— method channel handlerservice/LocationTrackingService.kt— foreground servicelocation/HeartbeatScheduler.kt— AlarmManager-based heartbeat (not WorkManager — WorkManager runs in separate process and static callbacks are lost)
Key patterns & gotchas
- Permission flow:
locationAlways(background) requireslocationWhenInUseto be granted first. Always request WhenInUse → then Always. CheckisPermanentlyDeniedand callopenAppSettings()to direct user to app settings. - Battery optimization: Use
PowerManager.isIgnoringBatteryOptimizations(packageName)viaBridgeModuleto detect if app is excluded from Doze. Open settings withACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONSintent. - Dark theme: Set globally on
MaterialApp(scaffoldBackgroundColor,brightness: Brightness.dark,ColorScheme.dark). UseZoomPageTransitionsBuilderto avoid white flash on page transitions (notFadeUpwardsPageTransitionsBuilder). - Tracking config: Config dict must be passed to
startTracking()and also sent viaupdateConfig()separately. Both calls are needed. permission_screen.dartstate: Permissions are checked at init via_checkPermissions(). State must be re-checked after each request call, not assumed from the request result.preferences.dart: Uses staticSharedPreferencesinstance.Preferences.init()must be called beforerunApp().
Style conventions
- Monospace fonts, dark
#0d0d0dbackground, teal#00bcd4accent, green#00e676for active/granted states - All UI text uses
fontFamily: 'monospace' - Replace
Color.withOpacity(x)→Color.withValues(alpha: x)(deprecated in recent Flutter) - Remove unused imports before committing
Monorepo context
The sibling traccar-client-android directory is the original Java app — reference it for expected server request format: POST to serverUrl?id=deviceId&lat=...&lon=...×tamp=...&is_moving=0. The is_moving threshold is speed > 1.0 m/s.