refactor : base page

This commit is contained in:
2025-09-27 08:05:26 +03:30
parent 5ac8342bb3
commit a7c7442b49
6 changed files with 149 additions and 199 deletions

View File

@@ -3,7 +3,7 @@ import 'package:rasadyar_chicken/presentation/widget/app_bar.dart';
import 'package:rasadyar_chicken/presentation/widget/base_page/back_ground.dart';
import 'package:rasadyar_core/core.dart';
class ChickenBasePage extends StatefulWidget {
class ChickenBasePage extends GetView<BaseLogic> {
const ChickenBasePage({
super.key,
this.hasBack = true,
@@ -62,44 +62,13 @@ class ChickenBasePage extends StatefulWidget {
final BackGroundWidget? backGroundWidget;
@override
State<ChickenBasePage> createState() => _ChickenBasePageState();
}
class _ChickenBasePageState extends State<ChickenBasePage> {
int? _lastBackId;
@override
void initState() {
super.initState();
_lastBackId = widget.backId;
tLog(_lastBackId);
tLog(widget.backId);
}
@override
void didChangeDependencies() {
fLog('didChangeDependencies');
fLog(_lastBackId);
fLog(widget.backId);
super.didChangeDependencies();
}
@override
void didUpdateWidget(covariant ChickenBasePage oldWidget) {
dLog('didUpdateWidget');
dLog(_lastBackId);
dLog(widget.backId);
super.didUpdateWidget(oldWidget);
}
void _onFilterTap() {
if (widget.hasFilter && widget.filteringWidget != null) {
if (hasFilter && filteringWidget != null) {
final currentRoute = ModalRoute.of(Get.context!);
if (currentRoute?.isCurrent != true) return;
Get.bottomSheet(
widget.filteringWidget!,
filteringWidget!,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
@@ -109,61 +78,31 @@ class _ChickenBasePageState extends State<ChickenBasePage> {
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
iLog('PopScope onPopInvokedWithResult:==> ${widget.backId}');
iLog('PopScope onPopInvokedWithResult:==> $_lastBackId}');
iLog('PopScope onPopInvokedWithResult:==> ${widget.onPopScopTaped}');
iLog('PopScope onPopInvokedWithResult:==> ${widget.onBackTap}');
// چک کردن و مدیریت برگشت با backId
if (widget.backId != null) {
final navigatorState = Get.nestedKey(widget.backId!)?.currentState;
if (navigatorState != null && navigatorState.canPop()) {
Get.back(id: widget.backId!); // پاپ با استفاده از backId
} else {
// اگر هیچ صفحه‌ای برای پاپ موجود نیست
if (widget.onPopScopTaped != null) {
widget.onPopScopTaped!();
} else {
Get.back();
}
}
} else {
// اگر backId نداشته باشد
if (widget.onPopScopTaped != null) {
widget.onPopScopTaped!();
} else {
Get.back();
}
}
},
child: BasePage(
routes: widget.routes,
routesWidget: widget.routesWidget,
widgets: widget.widgets,
child: widget.child,
scrollable: widget.scrollable,
floatingActionButtonLocation: widget.floatingActionButtonLocation,
floatingActionButton: widget.floatingActionButton,
backGroundWidget: widget.backGroundWidget ?? chickenBackground(),
appBar: widget.isFullScreen
? null
: chickenAppBar(
isBase: widget.isBase,
hasBack: widget.isBase ? false : widget.hasBack,
onNewsTap: widget.onNewsTap,
hasFilter: widget.hasFilter,
hasSearch: widget.hasSearch,
hasNews: widget.hasNews,
backId: widget.backId,
onBackTap: widget.onBackTap,
hasNotification: widget.hasNotification,
onNotificationTap: widget.onNotificationTap,
onFilterTap: widget.hasFilter ? _onFilterTap : null,
//onSearchTap: widget.hasSearch ? controller.toggleSearch : null,
),
),
return BasePage(
routes: routes,
routesWidget: routesWidget,
widgets: widgets,
child: child,
scrollable: scrollable,
floatingActionButtonLocation: floatingActionButtonLocation,
floatingActionButton: floatingActionButton,
backGroundWidget: backGroundWidget ?? chickenBackground(),
appBar: isFullScreen
? null
: chickenAppBar(
isBase: isBase,
hasBack: isBase ? false : hasBack,
onNewsTap: onNewsTap,
hasFilter: hasFilter,
hasSearch: hasSearch,
hasNews: hasNews,
backId: backId,
onBackTap: onBackTap,
hasNotification: hasNotification,
onNotificationTap: onNotificationTap,
onFilterTap: hasFilter ? _onFilterTap : null,
//onSearchTap: widget.hasSearch ? controller.toggleSearch : null,
),
);
}
}