41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class GasStationRepository {
|
|
static final GasStationRepository _instance =
|
|
GasStationRepository._internal();
|
|
|
|
/// Singleton instance getter
|
|
factory GasStationRepository() => _instance;
|
|
|
|
//Constructor???
|
|
GasStationRepository._internal() {
|
|
//init for something
|
|
}
|
|
|
|
Future<dynamic> getGasStationsLocations(Map map) async {
|
|
List<dynamic> data = [];
|
|
var lat = map['lat'];
|
|
var lng = map['lng'];
|
|
var gas = map['gas'];
|
|
// Hier kannst du die Logik hinzufügen, um den Standort zu verwenden, z.B.
|
|
String baseUrl = dotenv.get('TANKSTOPS_BASE_URL');
|
|
String getGasLocationLink ='$baseUrl?latitude=$lat&longitude=$lng&fuelType=$gas&includeClosed=false';
|
|
final client = http.Client();
|
|
var response = await client.get(Uri.parse(getGasLocationLink),headers: {'Content-Type': 'application/json', 'charset': 'utf-8'});
|
|
//Response Data status
|
|
if (response.statusCode == 200) {
|
|
//Response is succsessful
|
|
data = json.decode(utf8.decode(response.bodyBytes)); //get response data
|
|
} else {
|
|
debugPrint(response.statusCode.toString());
|
|
}
|
|
client.close();
|
|
|
|
return data;
|
|
}
|
|
}
|