change app name, add route calculator

This commit is contained in:
2025-07-26 18:05:29 +01:00
parent 3bef606d41
commit 34f0e8d96d
24 changed files with 625 additions and 157 deletions

View File

@@ -7,15 +7,22 @@ class DataService extends ChangeNotifier {
DataService({required this.api});
// Homepage Data
HomepageStats? _homepageStats;
HomepageStats? get homepageStats => _homepageStats;
// Legs Data
List<Leg> _legs = [];
List<Leg> get legs => _legs;
// Traction Data
List<LocoSummary> _traction = [];
List<LocoSummary> get traction => _traction;
// Station Data
List<Station>? _cachedStations;
DateTime? _stationsFetchedAt;
bool _isHomepageLoading = false;
bool get isHomepageLoading => _isHomepageLoading;
@@ -84,4 +91,23 @@ class DataService extends ChangeNotifier {
.mileage ??
0;
}
Future<List<Station>> fetchStations() async {
final now = DateTime.now();
// If cache exists and is less than 30 minutes old, return it
if (_cachedStations != null &&
_stationsFetchedAt != null &&
now.difference(_stationsFetchedAt!) < Duration(minutes: 30)) {
return _cachedStations!;
}
final response = await api.get('/location');
final parsed = (response as List).map((e) => Station.fromJson(e)).toList();
_cachedStations = parsed;
_stationsFetchedAt = now;
return parsed;
}
}