From 141999d61c5bdffc4098348c2132e931fdfaf18f Mon Sep 17 00:00:00 2001 From: josiadmin Date: Sat, 26 Sep 2026 23:26:58 +0200 Subject: [PATCH] error wenn no econtrol API --- .vscode/launch.json | 8 +- lib/controller/gasstations_controller.dart | 99 ++++++++++++++-------- lib/pages/gasstations_view.dart | 62 +++++++++++++- webserver/flutter_bootstrap.js | 2 +- webserver/main.dart.js | 2 +- 5 files changed, 132 insertions(+), 41 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1131171..cff78dc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,8 +8,12 @@ "deviceId": "chrome", "toolArgs": [ "--web-port", - "5000" + "5000", + "--web-browser-flag", + "--disable-web-security", + "--web-browser-flag", + "--user-data-dir=C:/tmp/chrome_dev_test" ] } ] -} +} \ No newline at end of file diff --git a/lib/controller/gasstations_controller.dart b/lib/controller/gasstations_controller.dart index 30e766a..6906382 100644 --- a/lib/controller/gasstations_controller.dart +++ b/lib/controller/gasstations_controller.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'package:get/get.dart'; import '../models/econtrol_model.dart'; import '../services/geolocation_service.dart'; @@ -6,6 +7,7 @@ import '../services/econtrol_service.dart'; class GasstationsController extends GetxController { final isLoading = false.obs; final isLoadingLocation = false.obs; + final errorMessage = ''.obs; final eControlData = [].obs; @override @@ -22,51 +24,76 @@ class GasstationsController extends GetxController { Future _loadStationInfosList() async { isLoading.value = true; - var geolocationService = GeolocationService(); - var eControlService = EControlService(); + errorMessage.value = ''; - await geolocationService.getCurrentLocation(); - if (geolocationService.hasLocation) { - // Parallel Diesel und Benzin laden - final fuelData = await eControlService.getBothFuelData( - geolocationService.latitude, - geolocationService.longitude, - ); + try { + var geolocationService = GeolocationService(); + var eControlService = EControlService(); - List dieselStations = (fuelData['DIE'] as List) - .map((json) => EControlModel.fromJson(json)) - .toList(); + // Standort-Abfrage mit Timeout versehen (z. B. 8 Sekunden), + // falls der Browser/User bei der Rechtefreigabe blockiert oder hängt + await geolocationService + .getCurrentLocation() + .timeout( + const Duration(seconds: 8), + onTimeout: () { + throw TimeoutException('Standortabfrage hat zu lange gedauert.'); + }, + ); - List supStations = (fuelData['SUP'] as List) - .map((json) => EControlModel.fromJson(json)) - .toList(); + if (geolocationService.hasLocation) { + final fuelData = await eControlService.getBothFuelData( + geolocationService.latitude, + geolocationService.longitude, + ); - // Map zur Zusammenführung nach Tankstellen-ID - Map combinedMap = {}; + List dieselStations = (fuelData['DIE'] as List) + .map((json) => EControlModel.fromJson(json)) + .toList(); - for (var station in dieselStations) { - if (station.id != null) { - combinedMap[station.id!] = station; - } - } + List supStations = (fuelData['SUP'] as List) + .map((json) => EControlModel.fromJson(json)) + .toList(); - // 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; + Map combinedMap = {}; + + for (var station in dieselStations) { + if (station.id != null) { + combinedMap[station.id!] = station; } } - } - eControlData.value = combinedMap.values.toList(); + for (var supStation in supStations) { + if (supStation.id != null) { + if (combinedMap.containsKey(supStation.id)) { + 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(); + } else { + errorMessage.value = + 'Standort konnte nicht ermittelt werden. Bitte prüfen Sie Ihre Browser-Freigabe.'; + } + } on TimeoutException { + errorMessage.value = + 'Standortabfrage zeitlich überschritten. Bitte erlauben Sie den Standortzugriff im Browser.'; + } catch (e) { + errorMessage.value = + 'Fehler beim Laden der Daten: ${e.toString()}'; + } finally { + // Stellt sicher, dass das Lade-Icon auf jeden Fall verschwindet + isLoading.value = false; + update(); } - isLoading.value = false; - update(); + } + + void retry() { + _loadStationInfosList(); } } \ No newline at end of file diff --git a/lib/pages/gasstations_view.dart b/lib/pages/gasstations_view.dart index ffee80c..96c2694 100644 --- a/lib/pages/gasstations_view.dart +++ b/lib/pages/gasstations_view.dart @@ -62,7 +62,67 @@ class GasstationsPage extends GetView { ], ), ); - } else if (staCtrl.eControlData.isEmpty) { + } + // Anzeige bei Fehler/Unerreichbarkeit des E-Control Services + else if (staCtrl.errorMessage.isNotEmpty) { + return Center( + child: Container( + margin: const EdgeInsets.all(24), + padding: const EdgeInsets.all(32), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(10), + blurRadius: 10, + offset: const Offset(0, 5), + ), + ], + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.cloud_off, + size: 64, + color: Colors.red[400], + ), + const SizedBox(height: 16), + Text( + 'Service nicht erreichbar', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Colors.blueGrey[800], + ), + ), + const SizedBox(height: 8), + Text( + staCtrl.errorMessage.value, + style: TextStyle(fontSize: 14, color: Colors.grey[600]), + textAlign: TextAlign.center, + ), + const SizedBox(height: 20), + ElevatedButton.icon( + onPressed: () => staCtrl.retry(), + icon: const Icon(Icons.refresh), + label: const Text('Erneut versuchen'), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.blueGrey[800], + foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + ), + ], + ), + ), + ); + } + // Anzeige, wenn keine Tankstellen gefunden wurden + else if (staCtrl.eControlData.isEmpty) { return Center( child: Container( margin: const EdgeInsets.all(24), diff --git a/webserver/flutter_bootstrap.js b/webserver/flutter_bootstrap.js index 07a3fe1..57490ef 100644 --- a/webserver/flutter_bootstrap.js +++ b/webserver/flutter_bootstrap.js @@ -37,6 +37,6 @@ _flutter.buildConfig = {"engineRevision":"a4ce257c68517c1410f4b48ac9852ab5642a3f _flutter.loader.load({ serviceWorkerSettings: { - serviceWorkerVersion: "6339570" /* Flutter's service worker is deprecated and will be removed in a future Flutter release. */ + serviceWorkerVersion: "1649555018" /* Flutter's service worker is deprecated and will be removed in a future Flutter release. */ } }); diff --git a/webserver/main.dart.js b/webserver/main.dart.js index 92bf02f..f24baf1 100644 --- a/webserver/main.dart.js +++ b/webserver/main.dart.js @@ -91065,7 +91065,7 @@ o.w=a.i(0,"CreatedAt") if(s!=null&&r!=null){q=A.fw(s) if(q==null)q=0 p=A.fw(r) -o.x=B.d.a7(q*(p==null?0:p),3)}else o.x="0.00" +o.x=B.d.a7(q*(p==null?0:p),2)}else o.x="0.00" return o}, $S:549} A.aaJ.prototype={