Fixed notification pagination for all and unread
This commit is contained in:
@@ -21,22 +21,37 @@ class MobileNotificationPage extends StatefulWidget {
|
||||
class _MobileNotificationPageState extends State<MobileNotificationPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController controller;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
final ScrollController _scrollAll = ScrollController();
|
||||
final ScrollController _scrollUnread = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = TabController(length: 3, vsync: this);
|
||||
|
||||
_scrollController.addListener(() {
|
||||
final viewModel = context.read<NotificationViewModel>();
|
||||
if (_scrollController.position.pixels >=
|
||||
_scrollController.position.maxScrollExtent - 100 &&
|
||||
!viewModel.isLoading &&
|
||||
viewModel.hasMoreData) {
|
||||
final viewModel = context.read<NotificationViewModel>();
|
||||
|
||||
_scrollAll.addListener(() {
|
||||
if (_scrollAll.position.pixels >=
|
||||
_scrollAll.position.maxScrollExtent - 100 &&
|
||||
!viewModel.isLoadingAll &&
|
||||
viewModel.hasMoreAll) {
|
||||
viewModel.getNotifications(
|
||||
page: viewModel.currentPage + 1,
|
||||
isMobile: true,
|
||||
page: viewModel.currentPageAll + 1,
|
||||
isPagination: true,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
_scrollUnread.addListener(() {
|
||||
if (_scrollUnread.position.pixels >=
|
||||
_scrollUnread.position.maxScrollExtent - 100 &&
|
||||
!viewModel.isLoadingUnread &&
|
||||
viewModel.hasMoreUnread) {
|
||||
viewModel.getUnreadNotifications(
|
||||
page: viewModel.currentPageUnread + 1,
|
||||
isPagination: true,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -45,7 +60,8 @@ class _MobileNotificationPageState extends State<MobileNotificationPage>
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
_scrollController.dispose();
|
||||
_scrollAll.dispose();
|
||||
_scrollUnread.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -98,37 +114,43 @@ class _MobileNotificationPageState extends State<MobileNotificationPage>
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12.0.h()),
|
||||
viewModel.isLoading
|
||||
? Container()
|
||||
: Expanded(
|
||||
child: TabBarView(
|
||||
controller: controller,
|
||||
children: [
|
||||
NotificationAllTab(scrollController: _scrollController),
|
||||
NotificationUnreadTab(scrollController: _scrollController),
|
||||
NotificationImportantTab(
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (viewModel.isMoreLoading) ...[
|
||||
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: controller,
|
||||
children: [
|
||||
NotificationAllTab(scrollController: _scrollAll),
|
||||
NotificationUnreadTab(scrollController: _scrollUnread),
|
||||
const NotificationImportantTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
if (viewModel.isMoreLoadingAll)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: AppColors.secondary50),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (viewModel.isLoading &&
|
||||
(viewModel.notificationResponse?.data?.notifications?.isEmpty ??
|
||||
true)) ...[
|
||||
const Spacer(),
|
||||
const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.secondary50),
|
||||
|
||||
if (viewModel.isMoreLoadingUnread)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: AppColors.secondary50),
|
||||
),
|
||||
),
|
||||
|
||||
if ((viewModel.isLoadingAll &&
|
||||
(viewModel.allNotificationResponse?.data?.notifications?.isEmpty ?? true)) ||
|
||||
(viewModel.isLoadingUnread &&
|
||||
(viewModel.unreadNotificationResponse?.data?.notifications?.isEmpty ?? true)))
|
||||
const Expanded(
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: AppColors.secondary50),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user