248053270b
Delete old flat files, wire new DI in main.dart:
- Removed: gps_service.dart, config/, models/, providers/overlay_provider.dart,
screens/, services/gps_data_manager.dart, services/overlay_service.dart
- Kept: settings_provider.dart (thin, correct), logger.dart (shared util)
- main.dart now wires: LocationRepository → SpeedometerViewModel → SpeedometerView
- overlay_provider.dart deferred, stub in ui/features/overlay/
- flutter analyze: 30 info-level constant_identifier_names warnings (project convention),
zero errors, zero warnings — builds clean
New structure:
lib/
core/constants/ — gps, overlay, timing, speed_unit
core/theme/ — color_themes
data/
models/ — LocationData (immutable domain model)
services/ — GpsService (stateless wrapper), OverlayService (IPC)
repositories/ — LocationRepository (business logic, ChangeNotifier)
providers/ — SettingsProvider (thin, unchanged)
ui/
features/
speedometer/ — SpeedometerViewModel + SpeedometerView
overlay/ — Stub ViewModel + View (deferred)
shared/ — SpeedDisplay widget
services/ — Logger (shared util)
51 lines
1.9 KiB
Dart
51 lines
1.9 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../core/constants/speed_unit.dart';
|
|
import '../core/theme/color_themes.dart';
|
|
import '../services/logger.dart';
|
|
|
|
class SettingsProvider extends ChangeNotifier {
|
|
final SharedPreferences _prefs;
|
|
|
|
int _currentThemeIndex = 0;
|
|
SpeedUnit _currentUnit = SpeedUnit.kmh;
|
|
|
|
// Getters for read access
|
|
int get currentThemeIndex => _currentThemeIndex;
|
|
SpeedUnit get currentUnit => _currentUnit;
|
|
ColorTheme get currentTheme => ColorThemes.getTheme(_currentThemeIndex);
|
|
|
|
/// Constructor loads settings synchronously from pre-initialized SharedPreferences.
|
|
/// SharedPreferences MUST be initialized before constructing this provider.
|
|
SettingsProvider(this._prefs) {
|
|
_loadSettings();
|
|
Logger.info('Settings loaded: theme=$_currentThemeIndex, unit=${_currentUnit.label}', 'SettingsProvider');
|
|
}
|
|
|
|
void _loadSettings() {
|
|
_currentThemeIndex = _prefs.getInt('themeIndex') ?? 0;
|
|
final unitIndex = _prefs.getInt('unitIndex') ?? 0;
|
|
_currentUnit = SpeedUnit.values[unitIndex.clamp(0, SpeedUnit.values.length - 1)];
|
|
// No notifyListeners() — constructor runs before first build
|
|
}
|
|
|
|
/// Cycle to next theme with haptic feedback and persistence
|
|
void cycleTheme() {
|
|
HapticFeedback.lightImpact();
|
|
_currentThemeIndex = ColorThemes.getNextThemeIndex(_currentThemeIndex);
|
|
_prefs.setInt('themeIndex', _currentThemeIndex);
|
|
Logger.debug('Theme cycled to index $_currentThemeIndex', 'SettingsProvider');
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Cycle to next speed unit with haptic feedback and persistence
|
|
void cycleUnit() {
|
|
HapticFeedback.lightImpact();
|
|
_currentUnit = _currentUnit.next;
|
|
_prefs.setInt('unitIndex', _currentUnit.index);
|
|
Logger.debug('Unit cycled to ${_currentUnit.label}', 'SettingsProvider');
|
|
notifyListeners();
|
|
}
|
|
}
|