error wenn no econtrol API
This commit is contained in:
Vendored
+5
-1
@@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -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,51 +24,76 @@ class GasstationsController extends GetxController {
|
||||
|
||||
Future<void> _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<EControlModel> 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<EControlModel> 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<int, EControlModel> combinedMap = {};
|
||||
List<EControlModel> 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<EControlModel> 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<int, EControlModel> 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();
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
@@ -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. */
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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={
|
||||
|
||||
Reference in New Issue
Block a user