pre final ad services and correct call the services async

This commit is contained in:
2026-02-20 09:51:03 +01:00
parent 8349e2b496
commit 46f7416781
7 changed files with 479 additions and 207 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_tank_web_app/services/geolocation_service.dart';
import 'package:get/get.dart';
import 'package:geolocator/geolocator.dart';
import '../models/locationiq_model.dart';
@@ -62,43 +63,26 @@ class EditController extends GetxController {
}
Future<void> _requestLocationIQ() async {
bool serviceEnabled;
LocationPermission permission;
var geolocationService = GeolocationService();
var locationIQService = LocationIQService();
isLoadingLocation.value = true;
try {
isLoadingLocation.value = true;
await geolocationService.getCurrentLocation();
if (geolocationService.hasLocation) {
print(
'Aktuelle Position: ${geolocationService.latitude}, ${geolocationService.longitude}',
);
await locationIQService.fetchLocationIQ(
geolocationService.latitude,
geolocationService.longitude,
);
// 1. Prüfen, ob Standortdienste aktiviert sind
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Standortdienste sind deaktiviert.');
currentLocationIQ = locationIQService.locationIQ;
locationController.text =
currentLocationIQ?.address?.shortAddress ?? '';
} else {
throw Exception('Standort nicht verfügbar');
}
// 2. Berechtigungen prüfen
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Berechtigung verweigert.');
}
}
// 3. Position abrufen
Position position = await Geolocator.getCurrentPosition(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
),
);
// 4. Standort über Backend-Proxy abrufen
var lat = position.latitude;
var lon = position.longitude;
print('📍 Verwende LocationIQ für Geocoding...');
final LocationIQService locationIQService = LocationIQService();
await locationIQService.fetchLocationIQ(lat, lon);
currentLocationIQ = locationIQService.locationIQ;
locationController.text = currentLocationIQ?.address?.shortAddress ?? '';
} catch (e) {
Get.snackbar(
"Fehler",

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import '../models/econtrol_model.dart';
import '../services/geolocation_service.dart';
import '../services/econtrol_service.dart';
class GasstationsController extends GetxController {
@@ -23,59 +22,19 @@ class GasstationsController extends GetxController {
Future<void> _loadStationInfosList() async {
isLoading.value = true;
bool serviceEnabled;
if (eControlData.isNotEmpty) {
eControlData.clear();
}
final eControlService = EControlService();
LocationPermission permission;
try {
isLoadingLocation.value = true;
// 1. Prüfen, ob Standortdienste aktiviert sind
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Standortdienste sind deaktiviert.');
}
// 2. Berechtigungen prüfen
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return Future.error('Berechtigung verweigert.');
}
}
// 3. Position abrufen
Position position = await Geolocator.getCurrentPosition(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
),
);
// 4. Standort über Backend-Proxy abrufen
var lat = position.latitude;
var lon = position.longitude;
// Simulate fetching data from an API or database
await eControlService.getEControlData(
lat,
lon,
var gelocationService = 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',
);
eControlData.addAll(eControlService.eControlData);
} catch (e) {
Get.snackbar(
"Fehler",
"Standort konnte nicht abgerufen werden: $e",
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red[100],
colorText: Colors.red[900],
);
print("Fehler beim Abrufen des Standorts: $e");
} finally {
isLoadingLocation.value = false;
eControlData.value = listResult
.map((json) => EControlModel.fromJson(json))
.toList();
}
isLoading.value = false;
update();