Fixed notification pagination for all and unread
This commit is contained in:
@@ -40,6 +40,26 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
||||
Widget build(BuildContext context) {
|
||||
final viewModel = context.watch<NotificationViewModel>();
|
||||
|
||||
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 SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.backgroundColor,
|
||||
@@ -60,6 +80,7 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
||||
NotificationStrings.unread,
|
||||
NotificationStrings.important,
|
||||
],
|
||||
onTap: (_) => setState(() {}),
|
||||
),
|
||||
SizedBox(height: 12.0.h()),
|
||||
Padding(
|
||||
@@ -93,27 +114,25 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
||||
),
|
||||
),
|
||||
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: [
|
||||
@@ -131,14 +150,19 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
||||
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 +177,7 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
||||
children: [
|
||||
SizedBox(width: 5.0.w()),
|
||||
Text(
|
||||
viewModel.currentPage.toString(),
|
||||
currentPage.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 14.0.sp(),
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -181,7 +205,7 @@ class _DesktopNotificationPageState extends State<DesktopNotificationPage>
|
||||
),
|
||||
SizedBox(width: 5.0.w()),
|
||||
Text(
|
||||
viewModel.totalPages.toString(),
|
||||
totalPages.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 13.0.sp(),
|
||||
fontWeight: FontWeight.w400,
|
||||
|
||||
Reference in New Issue
Block a user