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,70 +1,17 @@
import '../models/econtrol_model.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
class EControlService {
late List<EControlModel> eControlData;
Future<void> getEControlData(double latitude, double longitude, String fuelType) async {
// Simulate fetching data from an API or database
await Future.delayed(Duration(seconds: 2)); // Simulate network delay
eControlData = [
EControlModel(
id: 1,
name: 'E-Control Station 1',
location: Location(
latitude: 47.93875449671056,
longitude: 13.762706553431048,
),
contact: Contact(
telephone: '+43 123 456789',
mail: '',
website: 'https://www.econtrol.at',
),
openingHours: [
OpeningHours(
day: 'Tuesday',
label: '08:00',
order: 1,
from: '08:00',
to: '18:00',
),
],
offerInformation: OfferInformation(
service: true,
selfService: true,
unattended: true,
),
paymentMethods: PaymentMethods(
cash: true,
debitCard: true,
creditCard: false,
others: '',
),
paymentArrangements: PaymentArrangements(
cooperative: false,
clubCard: true,
),
position: 1,
open: true,
distance: 0.5,
prices: [Prices(fuelType: 'DIE', amount: 1.445, label: 'Diesel')],
),
];
Future<List<dynamic>> getEControlData(
double latitude,
double longitude,
String fuelType,
) async {
// REST Service... URL
String apiUrl = 'https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=$latitude&longitude=$longitude&fuelType=$fuelType&includeClosed=false';
try {
var response = await http.get(Uri.parse(apiUrl));
if (response.statusCode == 200) {
eControlData.clear(); // Clear existing data before adding new results
// Parse the response and update eControlData
print('E-Control API response: ${response.body}');
eControlData = (response.body as List).map((json) => EControlModel.fromJson(json)).toList();
print('E-Control data parsed successfully: ${eControlData.length} stations found');
}
} catch (e) {
print('Error fetching E-Control data: $e');
}
String apiUrl =
'https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=$latitude&longitude=$longitude&fuelType=$fuelType&includeClosed=false';
var response = await http.get(Uri.parse(apiUrl));
print('${response.statusCode}');
return jsonDecode(response.body);
}
}

View File

@@ -0,0 +1,54 @@
import 'package:geolocator/geolocator.dart';
class GeolocationService {
late double latitude;
late double longitude;
late bool hasLocation;
Future<void> getCurrentLocation() async {
bool serviceEnabled = false;
LocationPermission permission;
try {
// 1. Prüfen, ob Standortdienste aktiviert sind
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Standortdienste sind deaktiviert.');
}
hasLocation = serviceEnabled;
// 2. Berechtigungen prüfen
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
hasLocation = true;
if (permission == LocationPermission.denied) {
hasLocation = false;
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
latitude = position.latitude;
longitude = position.longitude;
if(latitude > 0 && longitude > 0) {
hasLocation = true;
}
} catch (e) {
print("Fehler beim Abrufen des Standorts: $e");
hasLocation = false;
}
}
}

View File

@@ -11,32 +11,6 @@ class LocationIQService {
Future<void> fetchLocationIQ(double lat, double lon) async {
// https://eu1.locationiq.com/v1/reverse?key=$locationIQKey&lat=47.93875449671056&lon=13.762706553431048&format=json
// Simulierte Antwort (für Testzwecke)
locationIQ = LocationIQ(
placeId: '12345',
licence: 'Data © OpenStreetMap contributors',
osmType: 'node',
osmId: '67890',
lat: lat.toString(),
lon: lon.toString(),
displayName: 'Test Location',
address: Address(
houseNumber: '123',
road: 'Test Street',
village: 'Test Village',
county: 'Test County',
state: 'Test State',
postcode: '12345',
country: 'Test Country',
countryCode: 'TC',
),
boundingbox: [
'47.93875449671056',
'47.93875449671056',
'13.762706553431048',
'13.762706553431048',
],
);
// Http Request
var httpClient = http.Client();