feat : init statics
This commit is contained in:
89
packages/inspection/lib/presentation/pages/root/logic.dart
Normal file
89
packages/inspection/lib/presentation/pages/root/logic.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/presentation/pages/action/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/pages/inspection_map/view.dart';
|
||||
import 'package:rasadyar_inspection/presentation/pages/profile/view.dart';
|
||||
|
||||
|
||||
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
|
||||
|
||||
class RootLogic extends GetxController {
|
||||
RxInt currentIndex = 0.obs;
|
||||
List<Widget> pages = [InspectionMapPage(), 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
|
||||
void 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) {
|
||||
currentIndex.value = index;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
56
packages/inspection/lib/presentation/pages/root/view.dart
Normal file
56
packages/inspection/lib/presentation/pages/root/view.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
class RootPage extends GetView<RootLogic> {
|
||||
const RootPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ObxValue((currentIndex) {
|
||||
return Scaffold(
|
||||
body: ObxValue(
|
||||
(currentIndex) => IndexedStack(index: currentIndex.value, children: controller.pages),
|
||||
controller.currentIndex,
|
||||
),
|
||||
bottomNavigationBar: RBottomNavigation(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
items: [
|
||||
RBottomNavigationItem(
|
||||
label: 'نقشه',
|
||||
icon: Assets.vec.mapSvg.path,
|
||||
isSelected: currentIndex.value == 0,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
|
||||
controller.changePage(0);
|
||||
},
|
||||
),
|
||||
RBottomNavigationItem(
|
||||
label: 'اقدام',
|
||||
icon: Assets.vec.settingSvg.path,
|
||||
isSelected: currentIndex.value == 1,
|
||||
onTap: () {
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(1);
|
||||
},
|
||||
),
|
||||
|
||||
RBottomNavigationItem(
|
||||
label: 'پروفایل',
|
||||
icon: Assets.vec.profileCircleSvg.path,
|
||||
isSelected: currentIndex.value == 4,
|
||||
onTap: () {
|
||||
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
|
||||
|
||||
controller.changePage(4);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}, controller.currentIndex);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user