refactor : base page
This commit is contained in:
@@ -31,6 +31,7 @@ class PoultryActionPage extends GetView<PoultryActionLogic> {
|
||||
title: item.title,
|
||||
vecIcon: item.icon,
|
||||
onTap: () async {
|
||||
|
||||
Get.toNamed(item.route, id: poultryFirstKey);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:rasadyar_chicken/data/di/chicken_di.dart';
|
||||
import 'package:rasadyar_chicken/data/repositories/poultry_science/poultry_science_repository.dart';
|
||||
import 'package:rasadyar_chicken/presentation/pages/common/profile/view.dart';
|
||||
import 'package:rasadyar_chicken/presentation/pages/poultry_science/home/view.dart';
|
||||
import 'package:rasadyar_chicken/presentation/pages/poultry_science/poultry_action/view.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/pages.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
|
||||
import 'package:rasadyar_chicken/presentation/utils/utils.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
@@ -11,15 +14,35 @@ import 'package:rasadyar_core/core.dart';
|
||||
enum ErrorLocationType { serviceDisabled, permissionDenied, none }
|
||||
|
||||
class PoultryScienceRootLogic extends GetxController {
|
||||
RxInt currentPage = 1.obs;
|
||||
List<Widget> pages = [PoultryActionPage(), PoultryScienceHomePage(), ProfilePage()];
|
||||
|
||||
var tokenService = Get.find<TokenStorageService>();
|
||||
|
||||
late PoultryScienceRepository poultryRepository;
|
||||
|
||||
RxList<ErrorLocationType> errorLocationType = RxList();
|
||||
RxMap<int, dynamic> homeExpandedList = RxMap();
|
||||
DateTime? _lastBackPressed;
|
||||
|
||||
RxInt currentPage = 1.obs;
|
||||
|
||||
final pages = [
|
||||
Navigator(
|
||||
key: Get.nestedKey(poultryFirstKey),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
orElse: () => ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == ChickenRoutes.actionPoultryScience,
|
||||
),
|
||||
);
|
||||
|
||||
return buildRouteFromGetPage(page);
|
||||
},
|
||||
),
|
||||
PoultryScienceHomePage(),
|
||||
ProfilePage(),
|
||||
|
||||
|
||||
];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -62,4 +85,28 @@ class PoultryScienceRootLogic extends GetxController {
|
||||
return poultryFirstKey;
|
||||
}
|
||||
}
|
||||
|
||||
void popBackTaped(bool didPop, result) async {
|
||||
final nestedKeyId = getNestedKey();
|
||||
GlobalKey<NavigatorState>? currentNestedKey = Get.nestedKey(nestedKeyId);
|
||||
|
||||
if (currentNestedKey?.currentState?.canPop() == true) {
|
||||
Get.back(id: nestedKeyId);
|
||||
} else {
|
||||
final now = DateTime.now();
|
||||
if (_lastBackPressed == null ||
|
||||
now.difference(_lastBackPressed!) > Duration(seconds: 2)) {
|
||||
_lastBackPressed = now;
|
||||
Get.snackbar(
|
||||
'خروج از برنامه',
|
||||
'برای خروج دوباره بازگشت را بزنید',
|
||||
snackPosition: SnackPosition.TOP,
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: AppColor.warning,
|
||||
);
|
||||
} else {
|
||||
await SystemNavigator.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/pages.dart';
|
||||
import 'package:rasadyar_chicken/presentation/routes/routes.dart';
|
||||
import 'package:rasadyar_chicken/presentation/utils/nested_keys_utils.dart';
|
||||
import 'package:rasadyar_chicken/presentation/widget/base_page/view.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
@@ -9,98 +6,75 @@ import 'package:rasadyar_core/core.dart';
|
||||
import 'logic.dart';
|
||||
|
||||
class PoultryScienceRootPage extends GetView<PoultryScienceRootLogic> {
|
||||
PoultryScienceRootPage({super.key});
|
||||
|
||||
DateTime? _lastBackPressed;
|
||||
const PoultryScienceRootPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChickenBasePage(
|
||||
isFullScreen: true,
|
||||
child: ObxValue((data) {
|
||||
return Stack(
|
||||
children: [
|
||||
IndexedStack(
|
||||
children: [
|
||||
Navigator(
|
||||
key: Get.nestedKey(poultryFirstKey),
|
||||
onGenerateRoute: (settings) {
|
||||
final page = ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == settings.name,
|
||||
orElse: () => ChickenPages.pages.firstWhere(
|
||||
(e) => e.name == ChickenRoutes.actionPoultryScience,
|
||||
),
|
||||
);
|
||||
|
||||
return buildRouteFromGetPage(page);
|
||||
},
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: controller.popBackTaped,
|
||||
child: ChickenBasePage(
|
||||
isFullScreen: true,
|
||||
child: ObxValue((data) {
|
||||
return Stack(
|
||||
children: [
|
||||
IndexedStack(children: controller.pages, index: data.value),
|
||||
Positioned(
|
||||
right: 0,
|
||||
left: 0,
|
||||
bottom: 0,
|
||||
child: RBottomNavigation(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
items: [
|
||||
RBottomNavigationItem(
|
||||
label: 'عملیات',
|
||||
icon: Assets.vec.settingSvg.path,
|
||||
isSelected: controller.currentPage.value == 0,
|
||||
onTap: () {
|
||||
Get.nestedKey(
|
||||
poultrySecondKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(
|
||||
poultryFirstKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(0);
|
||||
},
|
||||
),
|
||||
RBottomNavigationItem(
|
||||
label: 'خانه',
|
||||
icon: Assets.vec.homeSvg.path,
|
||||
isSelected: controller.currentPage.value == 1,
|
||||
onTap: () {
|
||||
Get.nestedKey(
|
||||
poultryFirstKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(
|
||||
poultryThirdKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(1);
|
||||
},
|
||||
),
|
||||
RBottomNavigationItem(
|
||||
label: 'پروفایل',
|
||||
icon: Assets.vec.profileCircleSvg.path,
|
||||
isSelected: controller.currentPage.value == 2,
|
||||
onTap: () {
|
||||
Get.nestedKey(
|
||||
poultryFirstKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(
|
||||
poultrySecondKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(2);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(poultrySecondKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[1]),
|
||||
),
|
||||
Navigator(
|
||||
key: Get.nestedKey(poultryThirdKey),
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => controller.pages[2]),
|
||||
),
|
||||
],
|
||||
index: data.value,
|
||||
),
|
||||
Positioned(
|
||||
right: 0,
|
||||
left: 0,
|
||||
bottom: 0,
|
||||
child: RBottomNavigation(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
items: [
|
||||
RBottomNavigationItem(
|
||||
label: 'عملیات',
|
||||
icon: Assets.vec.settingSvg.path,
|
||||
isSelected: controller.currentPage.value == 0,
|
||||
onTap: () {
|
||||
Get.nestedKey(
|
||||
poultrySecondKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(
|
||||
poultryFirstKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(0);
|
||||
},
|
||||
),
|
||||
RBottomNavigationItem(
|
||||
label: 'خانه',
|
||||
icon: Assets.vec.homeSvg.path,
|
||||
isSelected: controller.currentPage.value == 1,
|
||||
onTap: () {
|
||||
Get.nestedKey(
|
||||
poultryFirstKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(
|
||||
poultryThirdKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(1);
|
||||
},
|
||||
),
|
||||
RBottomNavigationItem(
|
||||
label: 'پروفایل',
|
||||
icon: Assets.vec.profileCircleSvg.path,
|
||||
isSelected: controller.currentPage.value == 2,
|
||||
onTap: () {
|
||||
Get.nestedKey(
|
||||
poultryFirstKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
Get.nestedKey(
|
||||
poultrySecondKey,
|
||||
)?.currentState?.popUntil((route) => route.isFirst);
|
||||
controller.changePage(2);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}, controller.currentPage),
|
||||
],
|
||||
);
|
||||
}, controller.currentPage),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user