Skip to content

Commit

Permalink
last updates
Browse files Browse the repository at this point in the history
  • Loading branch information
arda-copur committed Sep 24, 2024
1 parent 97538a6 commit 26fdb85
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/feature/providers/location_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class LocationProvider with ChangeNotifier {
bool serviceEnabled;
LocationPermission permission;

// Konum servislerinin etkin olup olmadığını kontrol edin.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}

// Konum izni olup olmadığını kontrol edin.
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
Expand All @@ -28,14 +26,13 @@ class LocationProvider with ChangeNotifier {
}

if (permission == LocationPermission.deniedForever) {
return Future.error('Location permissions are permanently denied, we cannot request permissions.');
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}

// Konumu alın ve Firestore'a kaydedin.
_currentPosition = await Geolocator.getCurrentPosition();

// Firebase Auth ile şu anki kullanıcıyı alın
User? user = FirebaseAuth.instance.currentUser;
User? user = FirebaseAuth.instance.currentUser;
if (user != null) {
DocumentSnapshot userDoc = await FirebaseFirestore.instance
.collection('users')
Expand All @@ -47,13 +44,13 @@ class LocationProvider with ChangeNotifier {

await FirebaseFirestore.instance
.collection('locations')
.doc(user.uid) // Kullanıcıya özgü belgeyi güncelle
.doc(user.uid)
.set({
'latitude': _currentPosition!.latitude,
'longitude': _currentPosition!.longitude,
'name': name,
'homeCode': homeCode,
}, SetOptions(merge: true)); // Belgeyi güncellemek için `merge: true` kullanılır
'latitude': _currentPosition!.latitude,
'longitude': _currentPosition!.longitude,
'name': name,
'homeCode': homeCode,
}, SetOptions(merge: true));

notifyListeners();
}
Expand Down

0 comments on commit 26fdb85

Please sign in to comment.