This commit is contained in:
Dennis Nemec
2026-04-28 13:03:09 +02:00
parent de8668c11a
commit 2470299a10
53 changed files with 2409 additions and 1433 deletions

View File

@ -0,0 +1,34 @@
import 'package:hl_lieferservice/feature/cars/model/selection.dart';
import 'package:shared_preferences/shared_preferences.dart';
class CarSelectionRepository {
static const _keyDate = 'car_selection_date';
static const _keyCarId = 'car_selection_car_id';
static const _keyCarPlate = 'car_selection_car_plate';
/// Returns the stored [CarSelection], or null if nothing has been saved yet.
Future<CarSelection?> getSelection() async {
final prefs = await SharedPreferences.getInstance();
final dateString = prefs.getString(_keyDate);
final carId = prefs.getInt(_keyCarId);
final plate = prefs.getString(_keyCarPlate);
if (dateString == null || carId == null || plate == null) return null;
return CarSelection(
date: DateTime.parse(dateString),
selectedCarId: carId,
selectedCarPlate: plate,
);
}
/// Persists the given [selection] locally on this device.
Future<void> saveSelection(CarSelection selection) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_keyDate, selection.date.toIso8601String());
await prefs.setInt(_keyCarId, selection.selectedCarId!);
await prefs.setString(_keyCarPlate, selection.selectedCarPlate!);
}
}