error wenn no econtrol API

This commit is contained in:
2026-09-26 23:26:58 +02:00
parent d6bdc01281
commit 141999d61c
5 changed files with 132 additions and 41 deletions
+5 -1
View File
@@ -8,7 +8,11 @@
"deviceId": "chrome",
"toolArgs": [
"--web-port",
"5000"
"5000",
"--web-browser-flag",
"--disable-web-security",
"--web-browser-flag",
"--user-data-dir=C:/tmp/chrome_dev_test"
]
}
]
+32 -5
View File
@@ -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 = <EControlModel>[].obs;
@override
@@ -22,12 +24,24 @@ class GasstationsController extends GetxController {
Future<void> _loadStationInfosList() async {
isLoading.value = true;
errorMessage.value = '';
try {
var geolocationService = GeolocationService();
var eControlService = EControlService();
await geolocationService.getCurrentLocation();
// 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.');
},
);
if (geolocationService.hasLocation) {
// Parallel Diesel und Benzin laden
final fuelData = await eControlService.getBothFuelData(
geolocationService.latitude,
geolocationService.longitude,
@@ -41,7 +55,6 @@ class GasstationsController extends GetxController {
.map((json) => EControlModel.fromJson(json))
.toList();
// Map zur Zusammenführung nach Tankstellen-ID
Map<int, EControlModel> combinedMap = {};
for (var station in dieselStations) {
@@ -50,11 +63,9 @@ class GasstationsController extends GetxController {
}
}
// 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];
@@ -65,8 +76,24 @@ class GasstationsController extends GetxController {
}
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();
}
}
void retry() {
_loadStationInfosList();
}
}
+61 -1
View File
@@ -62,7 +62,67 @@ class GasstationsPage extends GetView<GasstationsController> {
],
),
);
} 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),
+1 -1
View File
@@ -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. */
}
});
+1 -1
View File
@@ -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={