feat : PopScope and there logic
This commit is contained in:
@@ -1,15 +1,43 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:rasadyar_chicken/chicken.dart';
|
import 'package:rasadyar_chicken/chicken.dart';
|
||||||
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
|
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
|
||||||
import 'package:rasadyar_core/core.dart';
|
import 'package:rasadyar_core/core.dart';
|
||||||
|
|
||||||
class RootPage extends GetView<RootLogic> {
|
class RootPage extends GetView<RootLogic> {
|
||||||
const RootPage({super.key});
|
RootPage({super.key});
|
||||||
|
|
||||||
|
DateTime? _lastBackPressed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ObxValue((data) {
|
return ObxValue((data) {
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (didPop, result) async {
|
||||||
|
final nestedKey = Get.nestedKey(controller.currentPage.value);
|
||||||
|
final currentNavigator = nestedKey?.currentState;
|
||||||
|
|
||||||
|
if (currentNavigator?.canPop() ?? false) {
|
||||||
|
currentNavigator?.pop();
|
||||||
|
} 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Scaffold(
|
||||||
backgroundColor: AppColor.bgLight,
|
backgroundColor: AppColor.bgLight,
|
||||||
body: IndexedStack(
|
body: IndexedStack(
|
||||||
children: [
|
children: [
|
||||||
@@ -29,7 +57,8 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
onGenerateRoute: (settings) {
|
onGenerateRoute: (settings) {
|
||||||
final page = ChickenPages.pages.firstWhere(
|
final page = ChickenPages.pages.firstWhere(
|
||||||
(e) => e.name == settings.name,
|
(e) => e.name == settings.name,
|
||||||
orElse: () => ChickenPages.pages.firstWhere((e) => e.name == ChickenRoutes.sale),
|
orElse: () =>
|
||||||
|
ChickenPages.pages.firstWhere((e) => e.name == ChickenRoutes.sale),
|
||||||
);
|
);
|
||||||
|
|
||||||
return buildRouteFromGetPage(page);
|
return buildRouteFromGetPage(page);
|
||||||
@@ -85,6 +114,7 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}, controller.currentPage);
|
}, controller.currentPage);
|
||||||
}
|
}
|
||||||
@@ -164,15 +194,20 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
height: 82,
|
height: 82,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: bgLabelColor,
|
color: bgLabelColor,
|
||||||
borderRadius: BorderRadius.only(topRight: Radius.circular(8), bottomRight: Radius.circular(8)),
|
borderRadius: BorderRadius.only(
|
||||||
|
topRight: Radius.circular(8),
|
||||||
|
bottomRight: Radius.circular(8),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
SvgGenImage.vec(
|
SvgGenImage.vec(iconPath).svg(
|
||||||
iconPath,
|
width: 24,
|
||||||
).svg(width: 24, height: 24, colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn)),
|
height: 24,
|
||||||
|
colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn),
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
title,
|
title,
|
||||||
textAlign: TextAlign.right,
|
textAlign: TextAlign.right,
|
||||||
@@ -187,7 +222,10 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: bgDescriptionColor,
|
color: bgDescriptionColor,
|
||||||
borderRadius: BorderRadius.only(topLeft: Radius.circular(8), bottomLeft: Radius.circular(8)),
|
borderRadius: BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(8),
|
||||||
|
bottomLeft: Radius.circular(8),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
@@ -275,9 +313,11 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: SvgGenImage.vec(
|
child: SvgGenImage.vec(iconPath).svg(
|
||||||
iconPath,
|
width: 24,
|
||||||
).svg(width: 24, height: 24, colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn)),
|
height: 24,
|
||||||
|
colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -286,7 +326,11 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget widelyUsed({required String title, required String iconPath, required VoidCallback onTap}) {
|
Widget widelyUsed({
|
||||||
|
required String title,
|
||||||
|
required String iconPath,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
}) {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@@ -525,15 +569,25 @@ class RootPage extends GetView<RootLogic> {
|
|||||||
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
style: AppFonts.yekan16Bold.copyWith(color: AppColor.blueNormal),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
buildRow('فروش و توزیع داخل استان (کیلوگرم)', model.stewardAllocationsWeight!.toInt().toString()),
|
buildRow(
|
||||||
buildRow('فروش و توزیع خارج استان (کیلوگرم)', model.freeSalesWeight!.toInt().toString()),
|
'فروش و توزیع داخل استان (کیلوگرم)',
|
||||||
|
model.stewardAllocationsWeight!.toInt().toString(),
|
||||||
|
),
|
||||||
|
buildRow(
|
||||||
|
'فروش و توزیع خارج استان (کیلوگرم)',
|
||||||
|
model.freeSalesWeight!.toInt().toString(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: const Center(child: CircularProgressIndicator()),
|
: const Center(child: CircularProgressIndicator()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget cardWidget({required String title, required String iconPath, required VoidCallback onTap}) {
|
Widget cardWidget({
|
||||||
|
required String title,
|
||||||
|
required String iconPath,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
}) {
|
||||||
return Container(
|
return Container(
|
||||||
width: Get.width / 4,
|
width: Get.width / 4,
|
||||||
height: 130,
|
height: 130,
|
||||||
|
|||||||
@@ -23,12 +23,11 @@ class BasePage extends StatefulWidget {
|
|||||||
this.onFilterTap,
|
this.onFilterTap,
|
||||||
this.onSearchTap,
|
this.onSearchTap,
|
||||||
this.filteringWidget,
|
this.filteringWidget,
|
||||||
}):assert(
|
}) : assert(
|
||||||
(routes != null ) || routesWidget != null,
|
(routes != null) || routesWidget != null,
|
||||||
'Either routes or routesWidget must be provided.',
|
'Either routes or routesWidget must be provided.',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
final List<String>? routes;
|
final List<String>? routes;
|
||||||
final Widget? routesWidget;
|
final Widget? routesWidget;
|
||||||
final List<Widget> widgets;
|
final List<Widget> widgets;
|
||||||
@@ -77,7 +76,10 @@ class _BasePageState extends State<BasePage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (didPop, result) => widget.onBackPressed,
|
||||||
|
child: Scaffold(
|
||||||
backgroundColor: AppColor.bgLight,
|
backgroundColor: AppColor.bgLight,
|
||||||
appBar: chickenAppBar(
|
appBar: chickenAppBar(
|
||||||
hasBack: widget.isBase ? false : widget.hasBack,
|
hasBack: widget.isBase ? false : widget.hasBack,
|
||||||
@@ -100,6 +102,7 @@ class _BasePageState extends State<BasePage> {
|
|||||||
),
|
),
|
||||||
floatingActionButtonLocation: widget.floatingActionButtonLocation,
|
floatingActionButtonLocation: widget.floatingActionButtonLocation,
|
||||||
floatingActionButton: widget.floatingActionButton,
|
floatingActionButton: widget.floatingActionButton,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user