tasq/lib/utils/location_permission.dart

33 lines
1.2 KiB
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:flutter/foundation.dart' show kIsWeb;
import 'package:permission_handler/permission_handler.dart';
import '../services/permission_service.dart';
/// Helpers for requesting and checking the platform location permission.
///
/// Mirrors the pattern in [notification_permission.dart] so that location
/// can be requested at app launch and before location-dependent actions.
Future<PermissionStatus> requestLocationPermission() async {
if (kIsWeb) {
return PermissionStatus.granted;
}
return requestPermission(Permission.location);
}
/// Ensures location permission is granted. Returns `true` if granted.
///
/// Call on app launch and before check-in, check-out, or toggling location
/// tracking so the user always has the opportunity to grant permission.
Future<bool> ensureLocationPermission() async {
if (kIsWeb) return true;
final status = await Permission.location.status;
if (status.isGranted) return true;
if (status.isDenied || status.isRestricted || status.isLimited) {
final newStatus = await requestLocationPermission();
return newStatus.isGranted;
}
// permanently denied user must open settings
return false;
}