Files

86 lines
2.8 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
2025-05-21 14:43:26 +03:30
import 'logic.dart';
class RootPage extends GetView<RootLogic> {
RootPage({super.key});
2025-08-25 10:03:55 +03:30
// Extracted back-press
Future<void> _handleBackPress(BuildContext context) async {
final nestedKey = Get.nestedKey(controller.currentIndex.value);
final currentNavigator = nestedKey?.currentState;
if (currentNavigator?.canPop() ?? false) {
currentNavigator?.pop();
return;
}
final now = DateTime.now();
2025-08-25 15:44:27 +03:30
/*if (controller.lastBackPressed == null ||
2025-08-25 10:03:55 +03:30
now.difference(controller.lastBackPressed!) > const Duration(seconds: 2)) {
controller.lastBackPressed = now;
Get.snackbar(
'خروج از برنامه',
'برای خروج دوباره بازگشت را بزنید',
snackPosition: SnackPosition.TOP,
duration: const Duration(seconds: 2),
backgroundColor: AppColor.warning,
);
} else {
await SystemNavigator.pop();
2025-08-25 15:44:27 +03:30
}*/
2025-08-25 10:03:55 +03:30
}
@override
Widget build(BuildContext context) {
2025-05-21 14:43:26 +03:30
return ObxValue((currentIndex) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) async {
2025-08-25 10:03:55 +03:30
await _handleBackPress(context);
},
child: Scaffold(
body: IndexedStack(
2025-08-25 10:03:55 +03:30
children: controller.pages,
index: currentIndex.value,
sizing: StackFit.expand,
),
2025-06-30 08:51:11 +03:30
bottomNavigationBar: RBottomNavigation(
2025-08-03 11:55:57 +03:30
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
items: [
2025-06-30 08:51:11 +03:30
RBottomNavigationItem(
2025-08-03 11:55:57 +03:30
label: 'نقشه',
icon: Assets.vec.mapSvg.path,
isSelected: currentIndex.value == 0,
2025-08-03 11:55:57 +03:30
onTap: () {
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
controller.changePage(0);
},
),
2025-06-30 08:51:11 +03:30
RBottomNavigationItem(
2025-08-03 11:55:57 +03:30
label: 'درخواست‌ها',
icon: Assets.vec.settingSvg.path,
isSelected: currentIndex.value == 1,
2025-08-03 11:55:57 +03:30
onTap: () {
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
controller.changePage(1);
},
),
2025-06-30 08:51:11 +03:30
RBottomNavigationItem(
label: 'پروفایل',
2025-08-03 11:55:57 +03:30
icon: Assets.vec.profileCircleSvg.path,
isSelected: currentIndex.value == 2,
2025-08-03 11:55:57 +03:30
onTap: () {
Get.nestedKey(1)?.currentState?.popUntil((route) => route.isFirst);
Get.nestedKey(0)?.currentState?.popUntil((route) => route.isFirst);
controller.changePage(2);
},
),
],
),
2025-05-21 14:43:26 +03:30
),
);
}, controller.currentIndex);
}
}