Files
rasadyar_application/packages/chicken/lib/presentation/widget/base_page/view.dart
2025-09-25 17:25:55 +03:30

170 lines
5.1 KiB
Dart

import 'package:flutter/material.dart';
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 {
const ChickenBasePage({
super.key,
this.hasBack = true,
this.hasFilter = true,
this.hasSearch = true,
this.isBase = false,
this.hasNotification = false,
this.hasNews = false,
this.backId,
this.onBackTap,
this.onFilterTap,
this.onSearchTap,
this.onNewsTap,
this.onNotificationTap,
this.onSearchChanged,
this.routes,
this.routesWidget,
this.widgets,
this.child,
this.scrollable = false,
this.floatingActionButtonLocation,
this.floatingActionButton,
this.filteringWidget,
this.backGroundWidget,
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;
final VoidCallback? onNotificationTap;
final List<String>? routes;
final Breadcrumb? routesWidget;
final List<Widget>? widgets;
final Widget? child;
final bool scrollable;
final FloatingActionButtonLocation? floatingActionButtonLocation;
final Widget? floatingActionButton;
final Widget? filteringWidget;
final void Function(String?)? onSearchChanged;
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) {
final currentRoute = ModalRoute.of(Get.context!);
if (currentRoute?.isCurrent != true) return;
Get.bottomSheet(
widget.filteringWidget!,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
);
}
}
@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,
),
),
);
}
}