2026-08-23 17:16:43 +09:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
import '../../../core/constants/speed_unit.dart';
|
|
|
|
|
import '../../../data/models/location_data.dart';
|
|
|
|
|
import '../../../data/repositories/location_repository.dart';
|
2026-08-23 17:32:29 +09:00
|
|
|
import '../../../providers/settings_provider.dart';
|
2026-08-23 17:16:43 +09:00
|
|
|
|
|
|
|
|
/// ViewModel for the speedometer UI.
|
|
|
|
|
///
|
|
|
|
|
/// Thin state manager — subscribes to [LocationRepository] and exposes
|
|
|
|
|
/// the current display state to the view. No data-layer logic here.
|
|
|
|
|
class SpeedometerViewModel extends ChangeNotifier {
|
|
|
|
|
final LocationRepository _repository;
|
2026-08-23 23:26:03 +09:00
|
|
|
final SettingsProvider _settings;
|
2026-08-23 17:16:43 +09:00
|
|
|
|
2026-08-23 23:26:03 +09:00
|
|
|
SpeedUnit get displayUnit => _settings.currentUnit;
|
2026-08-23 17:32:29 +09:00
|
|
|
LocationData get displayData => _repository.currentData;
|
|
|
|
|
String get displaySpeedText => _repository.currentData.displaySpeed;
|
|
|
|
|
String get displayHeading => _repository.currentData.displayHeading;
|
|
|
|
|
bool get isSpeedValid => _repository.currentData.isSpeedValid;
|
|
|
|
|
bool get isHeadingValid => _repository.currentData.isHeadingValid;
|
2026-08-23 17:16:43 +09:00
|
|
|
|
2026-08-23 23:26:03 +09:00
|
|
|
SpeedometerViewModel(this._repository, this._settings);
|
2026-08-23 17:16:43 +09:00
|
|
|
|
|
|
|
|
double get displaySpeed {
|
2026-08-23 17:32:29 +09:00
|
|
|
return displayUnit.convert(_repository.currentData.speed);
|
2026-08-23 17:16:43 +09:00
|
|
|
}
|
|
|
|
|
}
|