commit 170825 daham Rechner
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:appwrite/models.dart' as models;
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
@@ -8,13 +9,11 @@ import '../../data/models/project_info.dart';
|
||||
///
|
||||
/// It provides a helper method to ping the server.
|
||||
class AppwriteRepository {
|
||||
|
||||
static const String pingPath = "/ping";
|
||||
// static const String appwriteProjectId = String.fromEnvironment('APPWRITE_PROJECT_ID');
|
||||
// static const String appwriteProjectName = String.fromEnvironment('APPWRITE_PROJECT_NAME');
|
||||
// static const String appwritePublicEndpoint = String.fromEnvironment('APPWRITE_PUBLIC_ENDPOINT');
|
||||
|
||||
|
||||
final Client _client = Client()
|
||||
.setProject(dotenv.get('APPWRITE_PROJECT_ID'))
|
||||
.setEndpoint(dotenv.get('APPWRITE_PUBLIC_ENDPOINT'));
|
||||
@@ -71,4 +70,27 @@ class AppwriteRepository {
|
||||
String _getCurrentDate() {
|
||||
return DateFormat("MMM dd, HH:mm").format(DateTime.now());
|
||||
}
|
||||
|
||||
Future<dynamic> logout() async =>
|
||||
await _account.deleteSession(sessionId: 'current');
|
||||
|
||||
Future<models.Session> login(Map map) async =>
|
||||
await _account.createEmailPasswordSession(
|
||||
email: map['email'],
|
||||
password: map['password'],
|
||||
);
|
||||
|
||||
Future<models.Session> signUpAnonymus() async =>
|
||||
await _account.createAnonymousSession();
|
||||
|
||||
Future<models.User> signup(Map map) async => _account.create(
|
||||
userId: ID.unique(),
|
||||
email: map['email'],
|
||||
password: map['password'],
|
||||
name: map['name'],
|
||||
);
|
||||
|
||||
Future<models.User> get getCurrentUser => _account.get();
|
||||
|
||||
createTankStop(Map<String, dynamic> map) {}
|
||||
}
|
||||
|
||||
97
lib/data/repository/location_repository.dart
Normal file
97
lib/data/repository/location_repository.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
|
||||
class LocationRepository {
|
||||
|
||||
static final LocationRepository _instance = LocationRepository._internal();
|
||||
|
||||
/// Singleton instance getter
|
||||
factory LocationRepository() => _instance;
|
||||
|
||||
//Constructor???
|
||||
LocationRepository._internal() {
|
||||
//init for something
|
||||
}
|
||||
|
||||
|
||||
/// Überprüft, ob der Standortdienst aktiviert ist.
|
||||
Future<bool> isLocationServiceEnabled() async {
|
||||
return await Geolocator.isLocationServiceEnabled();
|
||||
}
|
||||
|
||||
/// Fragt die Berechtigung für den Standort ab.
|
||||
Future<LocationPermission> checkPermission() async {
|
||||
return await Geolocator.checkPermission();
|
||||
}
|
||||
|
||||
/// Fordert die Berechtigung für den Standort an.
|
||||
Future<LocationPermission> requestPermission() async {
|
||||
return await Geolocator.requestPermission();
|
||||
}
|
||||
|
||||
/// Liefert die aktuelle Position des Geräts.
|
||||
/// Wirft eine Exception, wenn der Dienst nicht aktiviert ist oder keine Berechtigung vorliegt.
|
||||
Future<Position> getCurrentPosition() async {
|
||||
bool serviceEnabled = await isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
// Standortdienste sind nicht aktiviert.
|
||||
return Future.error('Location services are disabled.');
|
||||
}
|
||||
|
||||
LocationPermission permission = await checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
// Berechtigungen sind verweigert.
|
||||
return Future.error('Location permissions are denied');
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
// Berechtigungen sind dauerhaft verweigert.
|
||||
return Future.error(
|
||||
'Location permissions are permanently denied, we cannot request permissions.',
|
||||
);
|
||||
}
|
||||
|
||||
// Wenn alles in Ordnung ist, die Position zurückgeben.
|
||||
return await Geolocator.getCurrentPosition();
|
||||
}
|
||||
|
||||
Future<String> getNearbyLocation(Map map) async {
|
||||
String locationOrt = '?';
|
||||
var lat = map['lat'];
|
||||
var lng = map['lng'];
|
||||
// Hier kannst du die Logik hinzufügen, um den Standort zu verwenden, z.B.
|
||||
String ptvGeoLink =
|
||||
'https://api.myptv.com/geocoding/v1/locations/by-position/$lat/$lng?language=de&apiKey=${dotenv.get('PTV_GEOLINK_API_KEY')}';
|
||||
final client = http.Client();
|
||||
var response = await client.get(
|
||||
Uri.parse(ptvGeoLink),
|
||||
headers: {'Content-Type': 'application/json', 'charset': 'utf-8'},
|
||||
);
|
||||
//Response Data status
|
||||
if (response.statusCode == 200) {
|
||||
//Response is succsessful
|
||||
Map<String, dynamic> data = json.decode(
|
||||
utf8.decode(response.bodyBytes),
|
||||
); //get response data
|
||||
Map<String, dynamic> mapOfAddressfromPosition =
|
||||
data['locations'][0]['address']; //get response address of position
|
||||
if (mapOfAddressfromPosition.isNotEmpty) {
|
||||
locationOrt =
|
||||
'${mapOfAddressfromPosition['street'].toString()} ${mapOfAddressfromPosition['houseNumber'].toString()}, ${mapOfAddressfromPosition['postalCode'].toString()} ${mapOfAddressfromPosition['city'].toString()}';
|
||||
}
|
||||
} else {
|
||||
debugPrint(response.statusCode.toString());
|
||||
}
|
||||
client.close();
|
||||
|
||||
return locationOrt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user