add benzin to gasview

This commit is contained in:
2026-09-25 21:17:36 +02:00
parent 9a4c5cd82a
commit 44fa19b89f
4 changed files with 143 additions and 78 deletions
+40 -10
View File
@@ -22,21 +22,51 @@ class GasstationsController extends GetxController {
Future<void> _loadStationInfosList() async {
isLoading.value = true;
var gelocationService = GeolocationService();
var geolocationService = GeolocationService();
var eControlService = EControlService();
// check if location is available
await gelocationService.getCurrentLocation();
if (gelocationService.hasLocation) {
var listResult = await eControlService.getEControlData(
gelocationService.latitude,
gelocationService.longitude,
'DIE',
await geolocationService.getCurrentLocation();
if (geolocationService.hasLocation) {
// Parallel Diesel und Benzin laden
final fuelData = await eControlService.getBothFuelData(
geolocationService.latitude,
geolocationService.longitude,
);
eControlData.value = listResult
List<EControlModel> dieselStations = (fuelData['DIE'] as List)
.map((json) => EControlModel.fromJson(json))
.toList();
List<EControlModel> supStations = (fuelData['SUP'] as List)
.map((json) => EControlModel.fromJson(json))
.toList();
// Map zur Zusammenführung nach Tankstellen-ID
Map<int, EControlModel> combinedMap = {};
for (var station in dieselStations) {
if (station.id != null) {
combinedMap[station.id!] = station;
}
}
// Benzin-Preise in dieselben Tankstellen-Objekte mergen
for (var supStation in supStations) {
if (supStation.id != null) {
if (combinedMap.containsKey(supStation.id)) {
// Falls Tankstelle schon existiert, füge Benzin-Preis hinzu
final existingPrices = combinedMap[supStation.id!]!.prices ?? [];
final supPrices = supStation.prices ?? [];
combinedMap[supStation.id!]!.prices = [...existingPrices, ...supPrices];
} else {
combinedMap[supStation.id!] = supStation;
}
}
}
eControlData.value = combinedMap.values.toList();
}
isLoading.value = false;
update();
}
}
}