Fixed notification pagination for all and unread

This commit is contained in:
llsajjad
2025-09-27 08:54:11 +03:30
parent e432853478
commit 811a1c1385
9 changed files with 371 additions and 189 deletions
@@ -25,6 +25,7 @@ class TabletNotificationPage extends StatefulWidget {
class _TabletNotificationPageState extends State<TabletNotificationPage>
with SingleTickerProviderStateMixin {
late TabController controller;
final GlobalKey<ScaffoldState> key = GlobalKey();
@override
void initState() {
@@ -41,7 +42,25 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
@override
Widget build(BuildContext context) {
final viewModel = context.watch<NotificationViewModel>();
final GlobalKey<ScaffoldState> key = GlobalKey();
final activeIndex = controller.index;
int currentPage = 1;
int totalPages = 1;
bool isLoading = false;
if (activeIndex == 0) {
currentPage = viewModel.currentPageAll;
totalPages = viewModel.totalPagesAll;
isLoading = viewModel.isLoadingAll;
} else if (activeIndex == 1) {
currentPage = viewModel.currentPageUnread;
totalPages = viewModel.totalPagesUnread;
isLoading = viewModel.isLoadingUnread;
} else {
currentPage = viewModel.currentPageImportant;
totalPages = viewModel.totalPagesImportant;
isLoading = viewModel.isLoadingImportant;
}
return Scaffold(
key: key,
@@ -63,6 +82,7 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
NotificationStrings.unread,
NotificationStrings.important,
],
onTap: (_) => setState(() {}),
),
SizedBox(height: 12.0.h()),
Padding(
@@ -96,27 +116,25 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
),
),
SizedBox(height: 12.0.h()),
viewModel.isLoading
? Container()
: Expanded(
child: TabBarView(
controller: controller,
children: const [
NotificationAllTab(),
NotificationUnreadTab(),
NotificationImportantTab(),
],
if (isLoading)
const Expanded(
child: Center(
child: CircularProgressIndicator(
color: AppColors.secondary50,
),
),
if (viewModel.isLoading) ...[
const Spacer(),
const Center(
child: CircularProgressIndicator(
color: AppColors.secondary50,
)
else
Expanded(
child: TabBarView(
controller: controller,
children: const [
NotificationAllTab(),
NotificationUnreadTab(),
NotificationImportantTab(),
],
),
),
const Spacer(),
],
SizedBox(height: 10.0.h()),
Row(
children: [
@@ -134,14 +152,19 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
onTap: () async {
final selectedPage = await showDialog<int>(
context: context,
builder:
(context) => PageSelectionDialog(
totalPages: viewModel.totalPages,
),
builder: (context) => PageSelectionDialog(
totalPages: totalPages,
),
);
if (selectedPage != null) {
viewModel.jumpToPage(selectedPage);
if (activeIndex == 0) {
viewModel.jumpToPageAll(selectedPage);
} else if (activeIndex == 1) {
viewModel.jumpToPageUnread(selectedPage);
} else {
viewModel.jumpToPageImportant(selectedPage);
}
}
},
child: Container(
@@ -153,7 +176,7 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
children: [
SizedBox(width: 5.0.w()),
Text(
viewModel.currentPage.toString(),
currentPage.toString(),
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
@@ -184,7 +207,7 @@ class _TabletNotificationPageState extends State<TabletNotificationPage>
),
SizedBox(width: 5.0.w()),
Text(
viewModel.totalPages.toString(),
totalPages.toString(),
style: TextStyle(
fontSize: 13.0.sp(),
fontWeight: FontWeight.w400,