refactor : base page
This commit is contained in:
@@ -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 GetView<BaseLogic> {
|
||||
class ChickenBasePage extends StatefulWidget {
|
||||
const ChickenBasePage({
|
||||
super.key,
|
||||
this.hasBack = true,
|
||||
@@ -28,21 +28,22 @@ class ChickenBasePage extends GetView<BaseLogic> {
|
||||
this.floatingActionButton,
|
||||
this.filteringWidget,
|
||||
this.backGroundWidget,
|
||||
}) : assert(
|
||||
(routes != null) || routesWidget != null,
|
||||
'Either routes or routesWidget must be provided.',
|
||||
);
|
||||
this.isFullScreen = false,
|
||||
this.onPopScopTaped,
|
||||
});
|
||||
|
||||
//AppBar properties`
|
||||
final bool hasBack;
|
||||
final bool hasFilter;
|
||||
final bool hasSearch;
|
||||
final bool isBase;
|
||||
final bool isFullScreen;
|
||||
final bool hasNotification;
|
||||
final bool hasNews;
|
||||
final int? backId;
|
||||
|
||||
final VoidCallback? onBackTap;
|
||||
final VoidCallback? onPopScopTaped;
|
||||
final VoidCallback? onFilterTap;
|
||||
final VoidCallback? onSearchTap;
|
||||
final VoidCallback? onNewsTap;
|
||||
@@ -61,13 +62,44 @@ class ChickenBasePage extends GetView<BaseLogic> {
|
||||
|
||||
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 (hasFilter && filteringWidget != null) {
|
||||
if (widget.hasFilter && widget.filteringWidget != null) {
|
||||
final currentRoute = ModalRoute.of(Get.context!);
|
||||
if (currentRoute?.isCurrent != true) return;
|
||||
|
||||
Get.bottomSheet(
|
||||
filteringWidget!,
|
||||
widget.filteringWidget!,
|
||||
isScrollControlled: true,
|
||||
isDismissible: true,
|
||||
enableDrag: true,
|
||||
@@ -77,28 +109,60 @@ class ChickenBasePage extends GetView<BaseLogic> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BasePage(
|
||||
routes: routes,
|
||||
routesWidget: routesWidget,
|
||||
widgets: widgets,
|
||||
child: child,
|
||||
scrollable: scrollable,
|
||||
floatingActionButtonLocation: floatingActionButtonLocation,
|
||||
floatingActionButton: floatingActionButton,
|
||||
backGroundWidget: backGroundWidget ?? chickenBackground(),
|
||||
appBar: chickenAppBar(
|
||||
isBase: isBase,
|
||||
hasBack: isBase ? false : hasBack,
|
||||
onBackTap: onBackTap,
|
||||
onNewsTap: onNewsTap,
|
||||
hasFilter: hasFilter,
|
||||
hasSearch: hasSearch,
|
||||
hasNews: hasNews,
|
||||
hasNotification: hasNotification,
|
||||
backId: backId,
|
||||
onNotificationTap: onNotificationTap,
|
||||
onFilterTap: hasFilter ? _onFilterTap : null,
|
||||
onSearchTap: hasSearch ? controller.toggleSearch : null,
|
||||
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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user