import '../models/econtrol_model.dart'; import 'package:http/http.dart' as http; class EControlService { late List eControlData; Future 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')], ), ]; // 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'); } } }