Files
lab-app/lib/core/location/location_access_service.dart
T
2026-06-20 18:24:40 +03:00

31 lines
867 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:geolocator/geolocator.dart';
class LocationAccessService {
LocationAccessService._();
static Future<Position> getCurrentPosition() async {
final enabled = await Geolocator.isLocationServiceEnabled();
if (!enabled) {
throw Exception(
'Konum servisleri kapalı. Lütfen cihaz ayarlarından açın.');
}
var permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
}
if (permission == LocationPermission.denied) {
throw Exception('Konum izni verilmedi.');
}
if (permission == LocationPermission.deniedForever) {
throw Exception(
'Konum izni kalıcı olarak reddedildi. Lütfen cihaz ayarlarından izin verin.',
);
}
return Geolocator.getCurrentPosition();
}
}