From 811a1c1385c09945d1343e11c8dc1a0f7e3b156a Mon Sep 17 00:00:00 2001 From: llsajjad Date: Sat, 27 Sep 2025 08:54:11 +0330 Subject: [PATCH] Fixed notification pagination for all and unread --- lib/view_models/notification_view_model.dart | 284 ++++++++++++------ .../pages/d_notification_page.dart | 74 +++-- .../pages/m_notification_page.dart | 90 +++--- .../pages/t_notification_page.dart | 73 +++-- .../strings/notification_strings.dart | 1 + .../widgets/notification_all_tab.dart | 2 +- .../widgets/notification_important_tab.dart | 22 +- .../widgets/notification_unread_tab.dart | 2 +- lib/views/shared/main_tab_bar.dart | 12 +- 9 files changed, 371 insertions(+), 189 deletions(-) diff --git a/lib/view_models/notification_view_model.dart b/lib/view_models/notification_view_model.dart index 82150c9..ddbfe5e 100644 --- a/lib/view_models/notification_view_model.dart +++ b/lib/view_models/notification_view_model.dart @@ -5,80 +5,80 @@ import 'package:tm_app/data/repositories/notification_repository.dart'; import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart'; import 'package:tm_app/views/notification/strings/notification_strings.dart'; + class NotificationViewModel with ChangeNotifier { final NotificationsRepository _repository; NotificationViewModel({required NotificationsRepository repositoryViewModel}) - : _repository = repositoryViewModel { + : _repository = repositoryViewModel { WidgetsBinding.instance.addPostFrameCallback((_) { getNotifications(); getUnreadNotifications(); + getImportantNotifications(); }); } - bool _isLoading = false; - String? _errorMessage; - NotificationResponseModel? _notificationResponseModel; - - int currentPage = 1; static const int _pageSize = 10; - int _totalPages = 0; - bool _hasMoreData = true; - bool get isLoading => _isLoading; + String? _errorMessage; String? get errorMessage => _errorMessage; - NotificationResponseModel? get notificationResponse => - _notificationResponseModel; - bool get hasMoreData => _hasMoreData; - int get totalPages => _totalPages; - NotificationResponseModel? _unreadNotificationResponse; - bool _isUnreadLoading = false; + // All + NotificationResponseModel? allNotificationResponse; + bool isLoadingAll = false; + bool isMoreLoadingAll = false; + bool hasMoreAll = true; + int currentPageAll = 1; + int totalPagesAll = 0; - NotificationResponseModel? get unreadNotificationResponse => - _unreadNotificationResponse; - bool get isUnreadLoading => _isUnreadLoading; + // Unread + NotificationResponseModel? unreadNotificationResponse; + bool isLoadingUnread = false; + bool isMoreLoadingUnread = false; + bool hasMoreUnread = true; + int currentPageUnread = 1; + int totalPagesUnread = 0; - bool _isMoreLoading = false; - bool get isMoreLoading => _isMoreLoading; + // Important + NotificationResponseModel? importantNotificationResponse; + bool isLoadingImportant = false; + bool isMoreLoadingImportant = false; + bool hasMoreImportant = true; + int currentPageImportant = 1; + int totalPagesImportant = 0; - /// Fetch notifications - Future getNotifications({int page = 1, bool isMobile = false}) async { - if (isMobile && page > 1) { - _isMoreLoading = true; + + Future getNotifications({int page = 1, bool isPagination = false}) async { + if (isPagination) { + isMoreLoadingAll = true; } else { - _isLoading = true; + isLoadingAll = true; } notifyListeners(); - final int offset = _pageSize * page; - - final result = await _repository.getNotifications( - limit: _pageSize, - offset: offset, - ); + final int offset = (page - 1) * _pageSize; + final result = await _repository.getNotifications(limit: _pageSize, offset: offset); switch (result) { case Ok(): - if (isMobile && page > 1) { - final oldNotifications = - _notificationResponseModel?.data?.notifications ?? []; - - final newNotifications = result.value.data?.notifications ?? []; - - _notificationResponseModel = result.value.copyWith( - data: result.value.data?.copyWith( - notifications: [...oldNotifications, ...newNotifications], + final data = result.value; + if (isPagination && allNotificationResponse != null) { + final old = allNotificationResponse?.data?.notifications ?? []; + final fresh = data.data?.notifications ?? []; + allNotificationResponse = data.copyWith( + data: data.data?.copyWith( + notifications: [...old, ...fresh], ), ); } else { - _notificationResponseModel = result.value; + allNotificationResponse = data; } - currentPage = page; - _hasMoreData = - (result.value.data?.notifications?.length ?? 0) >= _pageSize; - _totalPages = result.value.data?.meta?.pages ?? 1; + _updateImportantFromAll(); + + currentPageAll = page; + totalPagesAll = data.data?.meta?.pages ?? 1; + hasMoreAll = (data.data?.notifications?.length ?? 0) >= _pageSize; break; case Error(): @@ -86,22 +86,136 @@ class NotificationViewModel with ChangeNotifier { break; } - _isLoading = false; - _isMoreLoading = false; + isLoadingAll = false; + isMoreLoadingAll = false; notifyListeners(); } - /// Jump to page - Future jumpToPage(int page) async { - if (_totalPages == 0 || page < 1 || page > _totalPages) { + Future getUnreadNotifications({int page = 1, bool isPagination = false}) async { + if (isPagination) { + isMoreLoadingUnread = true; + } else { + isLoadingUnread = true; + } + notifyListeners(); + + final int offset = (page - 1) * _pageSize; + final result = await _repository.getUnreadNotifications(limit: _pageSize, offset: offset); + + switch (result) { + case Ok(): + final data = result.value; + if (isPagination && unreadNotificationResponse != null) { + final old = unreadNotificationResponse?.data?.notifications ?? []; + final fresh = data.data?.notifications ?? []; + unreadNotificationResponse = data.copyWith( + data: data.data?.copyWith( + notifications: [...old, ...fresh], + ), + ); + } else { + unreadNotificationResponse = data; + } + + currentPageUnread = page; + totalPagesUnread = data.data?.meta?.pages ?? 1; + hasMoreUnread = (data.data?.notifications?.length ?? 0) >= _pageSize; + break; + + case Error(): + _errorMessage = result.error.toString(); + break; + } + + isLoadingUnread = false; + isMoreLoadingUnread = false; + notifyListeners(); + } + + Future getImportantNotifications({int page = 1, bool isPagination = false}) async { + if (isPagination) { + isMoreLoadingImportant = true; + } else { + isLoadingImportant = true; + } + notifyListeners(); + + final int offset = (page - 1) * _pageSize; + + final result = await _repository.getUnreadNotifications(limit: _pageSize, offset: offset); + + switch (result) { + case Ok(): + final data = result.value; + if (isPagination && importantNotificationResponse != null) { + final old = importantNotificationResponse?.data?.notifications ?? []; + final fresh = data.data?.notifications ?? []; + importantNotificationResponse = data.copyWith( + data: data.data?.copyWith( + notifications: [...old, ...fresh], + ), + ); + } else { + importantNotificationResponse = data; + } + + currentPageImportant = page; + totalPagesImportant = data.data?.meta?.pages ?? 1; + hasMoreImportant = (data.data?.notifications?.length ?? 0) >= _pageSize; + break; + + case Error(): + + _errorMessage = result.error.toString(); + + _updateImportantFromAll(); + break; + } + + isLoadingImportant = false; + isMoreLoadingImportant = false; + notifyListeners(); + } + + void _updateImportantFromAll() { + final all = allNotificationResponse?.data?.notifications ?? []; + final filtered = (all.where((n) { + final p = n.priority ?? ''; + return p.toLowerCase() == 'important'; + }).toList()); + + if (allNotificationResponse != null) { + importantNotificationResponse = allNotificationResponse!.copyWith( + data: allNotificationResponse!.data!.copyWith(notifications: filtered), + ); + } else { + importantNotificationResponse = null; + } + } + + Future jumpToPageAll(int page) async { + if (totalPagesAll == 0 || page < 1 || page > totalPagesAll) { return; } await getNotifications(page: page); } - /// Mark all as read + Future jumpToPageUnread(int page) async { + if (totalPagesUnread == 0 || page < 1 || page > totalPagesUnread) { + return; + } + await getUnreadNotifications(page: page); + } + + Future jumpToPageImportant(int page) async { + if (totalPagesImportant == 0 || page < 1 || page > totalPagesImportant) { + return; + } + await getImportantNotifications(page: page); + } + Future markAllAsRead(BuildContext context) async { - _isLoading = true; + isLoadingAll = true; _errorMessage = null; notifyListeners(); @@ -115,35 +229,39 @@ class NotificationViewModel with ChangeNotifier { case Ok>(): final response = result.value; final success = response['success'] as bool? ?? false; - final message = - response['message'] as String? ?? - NotificationStrings.unknownResponse; + final message = response['message'] as String? ?? NotificationStrings.unknownResponse; if (success) { - if (_notificationResponseModel?.data?.notifications != null) { - final updatedNotifications = - _notificationResponseModel!.data!.notifications! - .map((n) => n.copyWith(seen: true)) - .toList(); + if (allNotificationResponse?.data?.notifications != null) { + final updatedNotifications = allNotificationResponse!.data!.notifications! + .map((n) => n.copyWith(seen: true)) + .toList(); - _notificationResponseModel = _notificationResponseModel!.copyWith( - data: _notificationResponseModel!.data!.copyWith( + allNotificationResponse = allNotificationResponse!.copyWith( + data: allNotificationResponse!.data!.copyWith( notifications: updatedNotifications, ), ); - _unreadNotificationResponse = _unreadNotificationResponse?.copyWith( - data: _unreadNotificationResponse?.data?.copyWith( - notifications: [], - ), + unreadNotificationResponse = unreadNotificationResponse?.copyWith( + data: unreadNotificationResponse?.data?.copyWith(notifications: []), ); + + if (importantNotificationResponse?.data?.notifications != null) { + final updatedImportant = importantNotificationResponse!.data!.notifications! + .map((n) => n.copyWith(seen: true)) + .toList(); + + importantNotificationResponse = importantNotificationResponse!.copyWith( + data: importantNotificationResponse!.data!.copyWith( + notifications: updatedImportant, + ), + ); + } } if (context.mounted) { - AppToast.success( - context, - NotificationStrings.allNotificationMarkedAsRead, - ); + AppToast.success(context, NotificationStrings.allNotificationMarkedAsRead); } } else { _errorMessage = message; @@ -161,7 +279,7 @@ class NotificationViewModel with ChangeNotifier { break; } - _isLoading = false; + isLoadingAll = false; notifyListeners(); } @@ -182,28 +300,4 @@ class NotificationViewModel with ChangeNotifier { return '${difference.inDays} ${NotificationStrings.daysAgo}'; } } - - Future getUnreadNotifications({int page = 1}) async { - _isUnreadLoading = true; - notifyListeners(); - - final int offset = _pageSize * page; - - final result = await _repository.getUnreadNotifications( - limit: _pageSize, - offset: offset, - ); - - switch (result) { - case Ok(): - _unreadNotificationResponse = result.value; - break; - case Error(): - _errorMessage = result.error.toString(); - break; - } - - _isUnreadLoading = false; - notifyListeners(); - } } diff --git a/lib/views/notification/pages/d_notification_page.dart b/lib/views/notification/pages/d_notification_page.dart index ec40cc1..273efaa 100644 --- a/lib/views/notification/pages/d_notification_page.dart +++ b/lib/views/notification/pages/d_notification_page.dart @@ -40,6 +40,26 @@ class _DesktopNotificationPageState extends State Widget build(BuildContext context) { final viewModel = context.watch(); + 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 NotificationStrings.unread, NotificationStrings.important, ], + onTap: (_) => setState(() {}), ), SizedBox(height: 12.0.h()), Padding( @@ -93,27 +114,25 @@ class _DesktopNotificationPageState extends State ), ), 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 onTap: () async { final selectedPage = await showDialog( 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 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 ), SizedBox(width: 5.0.w()), Text( - viewModel.totalPages.toString(), + totalPages.toString(), style: TextStyle( fontSize: 13.0.sp(), fontWeight: FontWeight.w400, diff --git a/lib/views/notification/pages/m_notification_page.dart b/lib/views/notification/pages/m_notification_page.dart index 952a6c9..89802ab 100644 --- a/lib/views/notification/pages/m_notification_page.dart +++ b/lib/views/notification/pages/m_notification_page.dart @@ -21,22 +21,37 @@ class MobileNotificationPage extends StatefulWidget { class _MobileNotificationPageState extends State 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(); - if (_scrollController.position.pixels >= - _scrollController.position.maxScrollExtent - 100 && - !viewModel.isLoading && - viewModel.hasMoreData) { + final viewModel = context.read(); + + _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 @override void dispose() { controller.dispose(); - _scrollController.dispose(); + _scrollAll.dispose(); + _scrollUnread.dispose(); super.dispose(); } @@ -98,37 +114,43 @@ class _MobileNotificationPageState extends State ), ), 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(), - ], ], ), ); diff --git a/lib/views/notification/pages/t_notification_page.dart b/lib/views/notification/pages/t_notification_page.dart index ce73d68..73424d2 100644 --- a/lib/views/notification/pages/t_notification_page.dart +++ b/lib/views/notification/pages/t_notification_page.dart @@ -25,6 +25,7 @@ class TabletNotificationPage extends StatefulWidget { class _TabletNotificationPageState extends State with SingleTickerProviderStateMixin { late TabController controller; + final GlobalKey key = GlobalKey(); @override void initState() { @@ -41,7 +42,25 @@ class _TabletNotificationPageState extends State @override Widget build(BuildContext context) { final viewModel = context.watch(); - final GlobalKey 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 NotificationStrings.unread, NotificationStrings.important, ], + onTap: (_) => setState(() {}), ), SizedBox(height: 12.0.h()), Padding( @@ -96,27 +116,25 @@ class _TabletNotificationPageState extends State ), ), 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 onTap: () async { final selectedPage = await showDialog( 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 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 ), SizedBox(width: 5.0.w()), Text( - viewModel.totalPages.toString(), + totalPages.toString(), style: TextStyle( fontSize: 13.0.sp(), fontWeight: FontWeight.w400, diff --git a/lib/views/notification/strings/notification_strings.dart b/lib/views/notification/strings/notification_strings.dart index 531ce7f..adca448 100644 --- a/lib/views/notification/strings/notification_strings.dart +++ b/lib/views/notification/strings/notification_strings.dart @@ -22,4 +22,5 @@ class NotificationStrings { static const String reject = 'reject'; static const String info = 'info'; static const String noUnreadNotifications = 'No unread notifications'; + static const String noImportantNotifications = 'No important notifications'; } diff --git a/lib/views/notification/widgets/notification_all_tab.dart b/lib/views/notification/widgets/notification_all_tab.dart index 6d52fca..ba9e361 100644 --- a/lib/views/notification/widgets/notification_all_tab.dart +++ b/lib/views/notification/widgets/notification_all_tab.dart @@ -13,7 +13,7 @@ class NotificationAllTab extends StatelessWidget { Widget build(BuildContext context) { final viewModel = context.watch(); final notifications = - viewModel.notificationResponse?.data?.notifications ?? []; + viewModel.allNotificationResponse?.data?.notifications ?? []; return ListView.builder( controller: scrollController, diff --git a/lib/views/notification/widgets/notification_important_tab.dart b/lib/views/notification/widgets/notification_important_tab.dart index 840b883..ea20bd5 100644 --- a/lib/views/notification/widgets/notification_important_tab.dart +++ b/lib/views/notification/widgets/notification_important_tab.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:tm_app/view_models/notification_view_model.dart'; - +import 'package:tm_app/views/notification/strings/notification_strings.dart'; import 'notification_card.dart'; class NotificationImportantTab extends StatelessWidget { @@ -12,13 +12,25 @@ class NotificationImportantTab extends StatelessWidget { @override Widget build(BuildContext context) { final viewModel = context.watch(); - final allNotifications = - viewModel.notificationResponse?.data?.notifications ?? []; - final importantNotifications = allNotifications - .where((n) => n.priority?.toLowerCase() == 'important') + if (viewModel.isLoadingImportant) { + return const Center(child: CircularProgressIndicator()); + } + + final importantFromApi = viewModel.importantNotificationResponse?.data?.notifications ?? []; + + final allNotifications = viewModel.allNotificationResponse?.data?.notifications ?? []; + + final source = importantFromApi.isNotEmpty ? importantFromApi : allNotifications; + + final importantNotifications = source + .where((n) => (n.priority ?? '').toLowerCase() == 'important') .toList(); + if (importantNotifications.isEmpty) { + return const Center(child: Text(NotificationStrings.noImportantNotifications)); + } + return ListView.builder( controller: scrollController, itemCount: importantNotifications.length, diff --git a/lib/views/notification/widgets/notification_unread_tab.dart b/lib/views/notification/widgets/notification_unread_tab.dart index cc6afd5..0026638 100644 --- a/lib/views/notification/widgets/notification_unread_tab.dart +++ b/lib/views/notification/widgets/notification_unread_tab.dart @@ -14,7 +14,7 @@ class NotificationUnreadTab extends StatelessWidget { Widget build(BuildContext context) { final viewModel = context.watch(); - if (viewModel.isUnreadLoading) { + if (viewModel.isLoadingUnread){ return const Center(child: CircularProgressIndicator()); } diff --git a/lib/views/shared/main_tab_bar.dart b/lib/views/shared/main_tab_bar.dart index fe62df3..9b4a56f 100644 --- a/lib/views/shared/main_tab_bar.dart +++ b/lib/views/shared/main_tab_bar.dart @@ -1,13 +1,18 @@ import 'package:flutter/material.dart'; - import '../../core/theme/colors.dart'; import '../../core/utils/size_config.dart'; class MainTabBar extends StatefulWidget { - const MainTabBar({required this.controller, required this.titles, super.key}); + const MainTabBar({ + required this.controller, + required this.titles, + this.onTap, + super.key, + }); final TabController controller; final List titles; + final ValueChanged? onTap; @override State createState() => _MainTabBarState(); @@ -27,6 +32,8 @@ class _MainTabBarState extends State { ), alignment: Alignment.center, child: TabBar( + controller: widget.controller, + onTap: widget.onTap, indicatorSize: TabBarIndicatorSize.tab, dividerColor: Colors.transparent, indicator: BoxDecoration( @@ -40,7 +47,6 @@ class _MainTabBarState extends State { ), ], ), - controller: widget.controller, labelColor: AppColors.mainBlue, unselectedLabelColor: AppColors.grey60, labelStyle: TextStyle(fontSize: 16.0.sp(), fontWeight: FontWeight.w600),