feat : permission and location service sensor on\off in inspection feature
This commit is contained in:
@@ -2,16 +2,12 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/animation.dart';
|
import 'package:flutter/animation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_map/flutter_map.dart';
|
|
||||||
import 'package:flutter_map_animations/flutter_map_animations.dart';
|
|
||||||
import 'package:geolocator/geolocator.dart';
|
|
||||||
import 'package:latlong2/latlong.dart';
|
|
||||||
import 'package:rasadyar_core/core.dart';
|
|
||||||
import 'package:inspection/data/utils/marker_generator.dart';
|
import 'package:inspection/data/utils/marker_generator.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
enum BottomSheetStep { filter, markerSelected, markerDetails }
|
enum BottomSheetStep { filter, markerSelected, markerDetails }
|
||||||
|
|
||||||
class SupervisionFilterLogic extends GetxController
|
class InspectorFilterLogic extends GetxController
|
||||||
with GetTickerProviderStateMixin {
|
with GetTickerProviderStateMixin {
|
||||||
Rx<LatLng> currentLocation = LatLng(35.824891, 50.948025).obs;
|
Rx<LatLng> currentLocation = LatLng(35.824891, 50.948025).obs;
|
||||||
RxList<LatLng> allMarkers = <LatLng>[].obs;
|
RxList<LatLng> allMarkers = <LatLng>[].obs;
|
||||||
@@ -23,7 +19,6 @@ class SupervisionFilterLogic extends GetxController
|
|||||||
RxInt showIndex = 0.obs;
|
RxInt showIndex = 0.obs;
|
||||||
bool showSlideHint = true;
|
bool showSlideHint = true;
|
||||||
|
|
||||||
|
|
||||||
Rx<BottomSheetStep> bottomSheetStep = BottomSheetStep.filter.obs;
|
Rx<BottomSheetStep> bottomSheetStep = BottomSheetStep.filter.obs;
|
||||||
late Rx<SlidableController> slidController;
|
late Rx<SlidableController> slidController;
|
||||||
|
|
||||||
@@ -33,30 +28,13 @@ class SupervisionFilterLogic extends GetxController
|
|||||||
late Rx<DraggableBottomSheetController> sheetController;
|
late Rx<DraggableBottomSheetController> sheetController;
|
||||||
|
|
||||||
Future<void> determineCurrentPosition() async {
|
Future<void> determineCurrentPosition() async {
|
||||||
bool serviceEnabled;
|
|
||||||
LocationPermission permission;
|
|
||||||
|
|
||||||
serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
|
||||||
if (!serviceEnabled) {
|
|
||||||
return Future.error('Location services are disabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
permission = await Geolocator.checkPermission();
|
|
||||||
if (permission == LocationPermission.denied) {
|
|
||||||
permission = await Geolocator.requestPermission();
|
|
||||||
if (permission == LocationPermission.denied) {
|
|
||||||
return Future.error('Location permissions are denied.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (permission == LocationPermission.deniedForever) {
|
|
||||||
return Future.error('Location permissions are permanently denied.');
|
|
||||||
}
|
|
||||||
|
|
||||||
final position = await Geolocator.getCurrentPosition(
|
final position = await Geolocator.getCurrentPosition(
|
||||||
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
|
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
|
||||||
);
|
);
|
||||||
final latLng = LatLng(position.latitude, position.longitude);
|
final latLng = LatLng(position.latitude, position.longitude);
|
||||||
|
|
||||||
|
|
||||||
currentLocation.value = latLng;
|
currentLocation.value = latLng;
|
||||||
markers.add(latLng);
|
markers.add(latLng);
|
||||||
animatedMapController.animateTo(
|
animatedMapController.animateTo(
|
||||||
@@ -99,6 +77,7 @@ class SupervisionFilterLogic extends GetxController
|
|||||||
allMarkers.value = generatedMarkers;
|
allMarkers.value = generatedMarkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@@ -154,9 +133,8 @@ class SupervisionFilterLogic extends GetxController
|
|||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
determineCurrentPosition();
|
// determineCurrentPosition();
|
||||||
generatedMarkers();
|
generatedMarkers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> triggerSlidableAnimation() async {
|
Future<void> triggerSlidableAnimation() async {
|
||||||
@@ -167,11 +145,8 @@ class SupervisionFilterLogic extends GetxController
|
|||||||
showSlideHint = !showSlideHint;
|
showSlideHint = !showSlideHint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
|
|
||||||
super.onClose();
|
super.onClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import 'package:rasadyar_core/presentation/widget/buttons/fab.dart';
|
|||||||
|
|
||||||
import 'logic.dart';
|
import 'logic.dart';
|
||||||
|
|
||||||
class SupervisionFilterPage extends GetView<SupervisionFilterLogic> {
|
class SupervisionFilterPage extends GetView<InspectorFilterLogic> {
|
||||||
const SupervisionFilterPage({super.key});
|
const SupervisionFilterPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -1,16 +1,83 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:rasadyar_core/core.dart';
|
|
||||||
import 'package:inspection/presentation/action/view.dart';
|
import 'package:inspection/presentation/action/view.dart';
|
||||||
import 'package:inspection/presentation/filter/view.dart';
|
import 'package:inspection/presentation/filter/view.dart';
|
||||||
import 'package:inspection/presentation/profile/view.dart';
|
import 'package:inspection/presentation/profile/view.dart';
|
||||||
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
import 'package:rasadyar_core/data/utils.dart';
|
||||||
|
|
||||||
|
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
|
||||||
|
|
||||||
class RootLogic extends GetxController {
|
class RootLogic extends GetxController {
|
||||||
RxInt currentIndex = 0.obs;
|
RxInt currentIndex = 0.obs;
|
||||||
List<Widget> pages = [SupervisionFilterPage(), ActionPage(), ProfilePage()];
|
List<Widget> pages = [SupervisionFilterPage(), ActionPage(), ProfilePage()];
|
||||||
|
RxList<ErrorLocationType> errorLocationType = RxList();
|
||||||
|
|
||||||
|
Stream<bool> listenToLocationServiceStatus() {
|
||||||
|
return Geolocator.getServiceStatusStream().map((status) {
|
||||||
|
return status == ServiceStatus.enabled;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> locationServiceEnabled() async {
|
||||||
|
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||||
|
if (!serviceEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> checkPermission({bool request = false}) async {
|
||||||
|
try {
|
||||||
|
final LocationPermission permission = await Geolocator.checkPermission();
|
||||||
|
|
||||||
|
switch (permission) {
|
||||||
|
case LocationPermission.denied:
|
||||||
|
final LocationPermission requestResult = await Geolocator.requestPermission();
|
||||||
|
return requestResult != LocationPermission.denied &&
|
||||||
|
requestResult != LocationPermission.deniedForever;
|
||||||
|
|
||||||
|
case LocationPermission.deniedForever:
|
||||||
|
|
||||||
|
return request ? await Geolocator.openAppSettings() : false;
|
||||||
|
|
||||||
|
case LocationPermission.always:
|
||||||
|
case LocationPermission.whileInUse:
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
eLog(e);
|
||||||
|
return await Geolocator.openLocationSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
|
|
||||||
|
locationServiceEnabled().then((value) {
|
||||||
|
if (!value) {
|
||||||
|
errorLocationType.add(ErrorLocationType.serviceDisabled);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
checkPermission().then((value) {
|
||||||
|
if (!value) {
|
||||||
|
errorLocationType.add(ErrorLocationType.permissionDenied);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
listenToLocationServiceStatus().listen((event) {
|
||||||
|
if (!event) {
|
||||||
|
errorLocationType.add(ErrorLocationType.serviceDisabled);
|
||||||
|
} else {
|
||||||
|
errorLocationType.remove(ErrorLocationType.serviceDisabled);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void changePage(int index) {
|
void changePage(int index) {
|
||||||
|
|||||||
@@ -12,15 +12,112 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
|
ObxValue((errorType) {
|
||||||
|
if (errorType.isNotEmpty) {
|
||||||
|
if (errorType.contains(ErrorLocationType.serviceDisabled)) {
|
||||||
|
Future.microtask(() {
|
||||||
|
Get.defaultDialog(
|
||||||
|
title: 'خطا',
|
||||||
|
content: const Text('سرویس مکانیابی غیرفعال است'),
|
||||||
|
cancel: ROutlinedElevated(
|
||||||
|
text: 'بررسی مجدد',
|
||||||
|
width: 120,
|
||||||
|
textStyle: AppFonts.yekan16,
|
||||||
|
onPressed: () async {
|
||||||
|
var service = await controller.locationServiceEnabled();
|
||||||
|
eLog(service);
|
||||||
|
if (service) {
|
||||||
|
controller.errorLocationType.remove(
|
||||||
|
ErrorLocationType.serviceDisabled,
|
||||||
|
);
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
|
// Don't call Get.back() if service is still disabled
|
||||||
|
},
|
||||||
|
),
|
||||||
|
confirm: RElevated(
|
||||||
|
text: 'روشن کردن',
|
||||||
|
textStyle: AppFonts.yekan16,
|
||||||
|
width: 120,
|
||||||
|
onPressed: () async {
|
||||||
|
var res = await Geolocator.openLocationSettings();
|
||||||
|
if (res) {
|
||||||
|
var service =
|
||||||
|
await controller.locationServiceEnabled();
|
||||||
|
if (service) {
|
||||||
|
controller.errorLocationType.remove(
|
||||||
|
ErrorLocationType.serviceDisabled,
|
||||||
|
);
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
contentPadding: EdgeInsets.all(8),
|
||||||
|
onWillPop: () async {
|
||||||
|
return controller.errorLocationType.isEmpty;
|
||||||
|
},
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Future.microtask(() {
|
||||||
|
Get.defaultDialog(
|
||||||
|
title: 'خطا',
|
||||||
|
content: const Text(
|
||||||
|
' دسترسی به سرویس مکانیابی غیرفعال است',
|
||||||
|
),
|
||||||
|
cancel: ROutlinedElevated(
|
||||||
|
text: 'بررسی مجدد',
|
||||||
|
width: 120,
|
||||||
|
textStyle: AppFonts.yekan16,
|
||||||
|
onPressed: () async {
|
||||||
|
await controller.checkPermission();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
confirm: RElevated(
|
||||||
|
text: 'اجازه دادن',
|
||||||
|
textStyle: AppFonts.yekan16,
|
||||||
|
width: 120,
|
||||||
|
onPressed: () async {
|
||||||
|
var res = await controller.checkPermission(
|
||||||
|
request: true,
|
||||||
|
);
|
||||||
|
if (res) {
|
||||||
|
controller.errorLocationType.remove(
|
||||||
|
ErrorLocationType.permissionDenied,
|
||||||
|
);
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
contentPadding: EdgeInsets.all(8),
|
||||||
|
onWillPop: () async {
|
||||||
|
return controller.errorLocationType.isEmpty;
|
||||||
|
},
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}, controller.errorLocationType),
|
||||||
|
|
||||||
|
ObxValue(
|
||||||
|
(currentIndex) => IndexedStack(
|
||||||
|
index: currentIndex.value,
|
||||||
|
children: controller.pages,
|
||||||
|
),
|
||||||
|
controller.currentIndex,
|
||||||
|
),
|
||||||
|
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
child: WaveBottomNavigation(
|
child: WaveBottomNavigation(
|
||||||
items: [
|
items: [
|
||||||
WaveBottomNavigationItem(
|
WaveBottomNavigationItem(title: 'خانه', icon: Assets.vecMapSvg),
|
||||||
title: 'خانه',
|
|
||||||
icon:Assets.vecMapSvg,
|
|
||||||
),
|
|
||||||
WaveBottomNavigationItem(
|
WaveBottomNavigationItem(
|
||||||
title: 'عملیات',
|
title: 'عملیات',
|
||||||
icon: Assets.vecUserSvg,
|
icon: Assets.vecUserSvg,
|
||||||
@@ -32,13 +129,16 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
WaveBottomNavigationItem(
|
WaveBottomNavigationItem(
|
||||||
title: 'آمار',
|
title: 'آمار',
|
||||||
icon: Assets.vecDiagramSvg,
|
icon: Assets.vecDiagramSvg,
|
||||||
), WaveBottomNavigationItem(
|
),
|
||||||
|
WaveBottomNavigationItem(
|
||||||
title: 'تماس',
|
title: 'تماس',
|
||||||
icon: Assets.vecCallSvg,
|
icon: Assets.vecCallSvg,
|
||||||
), WaveBottomNavigationItem(
|
),
|
||||||
|
WaveBottomNavigationItem(
|
||||||
title: 'مکان ',
|
title: 'مکان ',
|
||||||
icon: Assets.vecGpsSvg,
|
icon: Assets.vecGpsSvg,
|
||||||
), WaveBottomNavigationItem(
|
),
|
||||||
|
WaveBottomNavigationItem(
|
||||||
title: 'تاریخ',
|
title: 'تاریخ',
|
||||||
icon: Assets.vecCalendarSvg,
|
icon: Assets.vecCalendarSvg,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ sealed class InspectionPages {
|
|||||||
page: () => RootPage(),
|
page: () => RootPage(),
|
||||||
binding: BindingsBuilder(() {
|
binding: BindingsBuilder(() {
|
||||||
Get.put(RootLogic());
|
Get.put(RootLogic());
|
||||||
Get.put(SupervisionFilterLogic());
|
Get.put(InspectorFilterLogic());
|
||||||
Get.lazyPut(() => LocationDetailsLogic(), fenix: true);
|
Get.lazyPut(() => LocationDetailsLogic(), fenix: true);
|
||||||
Get.lazyPut(() => ActionLogic(), fenix: true);
|
Get.lazyPut(() => ActionLogic(), fenix: true);
|
||||||
Get.lazyPut(() => ProfileLogic(), fenix: true);
|
Get.lazyPut(() => ProfileLogic(), fenix: true);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export 'package:persian_datetime_picker/persian_datetime_picker.dart';
|
|||||||
//Map and location
|
//Map and location
|
||||||
export 'package:latlong2/latlong.dart';
|
export 'package:latlong2/latlong.dart';
|
||||||
export 'package:flutter_map/flutter_map.dart';
|
export 'package:flutter_map/flutter_map.dart';
|
||||||
|
export 'package:geolocator/geolocator.dart';
|
||||||
|
export 'package:flutter_map_animations/flutter_map_animations.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user