Update codebase
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -63,24 +64,56 @@ class LoginCubit extends Cubit<LoginState> {
|
||||
/// تُستدعى أيضاً عند **العودة من إعدادات النظام**: بلا إعادة الفحص تبقى
|
||||
/// الشاشة عالقة بعد أن يمنح المستخدم الإذن يدوياً (حالة حافة من docs/39 §2).
|
||||
Future<void> checkLocationPermission() async {
|
||||
final status = await Permission.locationWhenInUse.status;
|
||||
if (status.isGranted || status.isLimited) {
|
||||
emit(state.copyWith(step: LoginStep.phone));
|
||||
final geoStatus = await Geolocator.checkPermission();
|
||||
if (geoStatus == LocationPermission.always ||
|
||||
geoStatus == LocationPermission.whileInUse) {
|
||||
emit(state.copyWith(
|
||||
step: LoginStep.phone,
|
||||
permissionPermanentlyDenied: false,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
final status = await Permission.locationWhenInUse.status;
|
||||
if (status.isGranted || status.isLimited) {
|
||||
emit(state.copyWith(
|
||||
step: LoginStep.phone,
|
||||
permissionPermanentlyDenied: false,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(state.copyWith(
|
||||
permissionPermanentlyDenied: status.isPermanentlyDenied,
|
||||
permissionPermanentlyDenied:
|
||||
geoStatus == LocationPermission.deniedForever ||
|
||||
status.isPermanentlyDenied,
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> requestLocationPermission() async {
|
||||
final status = await Permission.locationWhenInUse.request();
|
||||
if (status.isGranted || status.isLimited) {
|
||||
emit(state.copyWith(step: LoginStep.phone));
|
||||
final geoStatus = await Geolocator.requestPermission();
|
||||
if (geoStatus == LocationPermission.always ||
|
||||
geoStatus == LocationPermission.whileInUse) {
|
||||
emit(state.copyWith(
|
||||
step: LoginStep.phone,
|
||||
permissionPermanentlyDenied: false,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
final status = await Permission.locationWhenInUse.request();
|
||||
if (status.isGranted || status.isLimited) {
|
||||
emit(state.copyWith(
|
||||
step: LoginStep.phone,
|
||||
permissionPermanentlyDenied: false,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(state.copyWith(
|
||||
permissionPermanentlyDenied: status.isPermanentlyDenied,
|
||||
permissionPermanentlyDenied:
|
||||
geoStatus == LocationPermission.deniedForever ||
|
||||
status.isPermanentlyDenied,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user