error wenn no econtrol API
This commit is contained in:
Vendored
+5
-1
@@ -8,7 +8,11 @@
|
|||||||
"deviceId": "chrome",
|
"deviceId": "chrome",
|
||||||
"toolArgs": [
|
"toolArgs": [
|
||||||
"--web-port",
|
"--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 'package:get/get.dart';
|
||||||
import '../models/econtrol_model.dart';
|
import '../models/econtrol_model.dart';
|
||||||
import '../services/geolocation_service.dart';
|
import '../services/geolocation_service.dart';
|
||||||
@@ -6,6 +7,7 @@ import '../services/econtrol_service.dart';
|
|||||||
class GasstationsController extends GetxController {
|
class GasstationsController extends GetxController {
|
||||||
final isLoading = false.obs;
|
final isLoading = false.obs;
|
||||||
final isLoadingLocation = false.obs;
|
final isLoadingLocation = false.obs;
|
||||||
|
final errorMessage = ''.obs;
|
||||||
final eControlData = <EControlModel>[].obs;
|
final eControlData = <EControlModel>[].obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -22,51 +24,76 @@ class GasstationsController extends GetxController {
|
|||||||
|
|
||||||
Future<void> _loadStationInfosList() async {
|
Future<void> _loadStationInfosList() async {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
var geolocationService = GeolocationService();
|
errorMessage.value = '';
|
||||||
var eControlService = EControlService();
|
|
||||||
|
|
||||||
await geolocationService.getCurrentLocation();
|
try {
|
||||||
if (geolocationService.hasLocation) {
|
var geolocationService = GeolocationService();
|
||||||
// Parallel Diesel und Benzin laden
|
var eControlService = EControlService();
|
||||||
final fuelData = await eControlService.getBothFuelData(
|
|
||||||
geolocationService.latitude,
|
|
||||||
geolocationService.longitude,
|
|
||||||
);
|
|
||||||
|
|
||||||
List<EControlModel> dieselStations = (fuelData['DIE'] as List)
|
// Standort-Abfrage mit Timeout versehen (z. B. 8 Sekunden),
|
||||||
.map((json) => EControlModel.fromJson(json))
|
// falls der Browser/User bei der Rechtefreigabe blockiert oder hängt
|
||||||
.toList();
|
await geolocationService
|
||||||
|
.getCurrentLocation()
|
||||||
|
.timeout(
|
||||||
|
const Duration(seconds: 8),
|
||||||
|
onTimeout: () {
|
||||||
|
throw TimeoutException('Standortabfrage hat zu lange gedauert.');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
List<EControlModel> supStations = (fuelData['SUP'] as List)
|
if (geolocationService.hasLocation) {
|
||||||
.map((json) => EControlModel.fromJson(json))
|
final fuelData = await eControlService.getBothFuelData(
|
||||||
.toList();
|
geolocationService.latitude,
|
||||||
|
geolocationService.longitude,
|
||||||
|
);
|
||||||
|
|
||||||
// Map zur Zusammenführung nach Tankstellen-ID
|
List<EControlModel> dieselStations = (fuelData['DIE'] as List)
|
||||||
Map<int, EControlModel> combinedMap = {};
|
.map((json) => EControlModel.fromJson(json))
|
||||||
|
.toList();
|
||||||
|
|
||||||
for (var station in dieselStations) {
|
List<EControlModel> supStations = (fuelData['SUP'] as List)
|
||||||
if (station.id != null) {
|
.map((json) => EControlModel.fromJson(json))
|
||||||
combinedMap[station.id!] = station;
|
.toList();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Benzin-Preise in dieselben Tankstellen-Objekte mergen
|
Map<int, EControlModel> combinedMap = {};
|
||||||
for (var supStation in supStations) {
|
|
||||||
if (supStation.id != null) {
|
for (var station in dieselStations) {
|
||||||
if (combinedMap.containsKey(supStation.id)) {
|
if (station.id != null) {
|
||||||
// Falls Tankstelle schon existiert, füge Benzin-Preis hinzu
|
combinedMap[station.id!] = station;
|
||||||
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();
|
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(
|
return Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(24),
|
margin: const EdgeInsets.all(24),
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ _flutter.buildConfig = {"engineRevision":"a4ce257c68517c1410f4b48ac9852ab5642a3f
|
|||||||
|
|
||||||
_flutter.loader.load({
|
_flutter.loader.load({
|
||||||
serviceWorkerSettings: {
|
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(s!=null&&r!=null){q=A.fw(s)
|
||||||
if(q==null)q=0
|
if(q==null)q=0
|
||||||
p=A.fw(r)
|
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},
|
return o},
|
||||||
$S:549}
|
$S:549}
|
||||||
A.aaJ.prototype={
|
A.aaJ.prototype={
|
||||||
|
|||||||
Reference in New Issue
Block a user