diff --git a/lib/controllers/providers/api/notifications_provider.dart b/lib/controllers/providers/api/notifications_provider.dart index 7b9d5188..2909c363 100644 --- a/lib/controllers/providers/api/notifications_provider.dart +++ b/lib/controllers/providers/api/notifications_provider.dart @@ -191,9 +191,7 @@ class NotificationsProvider extends ChangeNotifier { final response = await ApiManager.instance.get(URLs.getUnreadNotificationCount, enableToastMessage: false); if (response.statusCode >= 200 && response.statusCode < 300) { final responseData = json.decode(response.body); - log('count response :: $responseData'); count = responseData['data']; - // Update the totalNotificationUnread property totalNotificationUnread = count ?? 0; notifyListeners(); } diff --git a/lib/dashboard_latest/dashboard_view.dart b/lib/dashboard_latest/dashboard_view.dart index 6de6e88b..7b240bdb 100644 --- a/lib/dashboard_latest/dashboard_view.dart +++ b/lib/dashboard_latest/dashboard_view.dart @@ -60,7 +60,7 @@ class _DashboardViewState extends State { _dashBoardProvider.setTabs(userType: userProvider.user!.type!, context: context); _dashBoardProvider.getDashBoardCount(usersType: userProvider.user!.type!); _dashBoardProvider.resetRequestDataList(); - + notificationsProvider.getUnreadCount(); if (userProvider.isHouseKeeper) { _dashBoardProvider.currentListIndex = 0; _dashBoardProvider.getRequestDetail( diff --git a/lib/dashboard_latest/widgets/app_bar_widget.dart b/lib/dashboard_latest/widgets/app_bar_widget.dart index a87ec4cb..32968c33 100644 --- a/lib/dashboard_latest/widgets/app_bar_widget.dart +++ b/lib/dashboard_latest/widgets/app_bar_widget.dart @@ -41,9 +41,6 @@ class _AppBarWidgetState extends State with TickerProviderStateMix void initState() { super.initState(); - // Profile section animation (left to right with fade) - getUnreadCount(); - _leftController = AnimationController( duration: const Duration(milliseconds: 600), vsync: this, @@ -101,12 +98,6 @@ class _AppBarWidgetState extends State with TickerProviderStateMix super.dispose(); } - Future getUnreadCount () async{ - NotificationsProvider notificationsProvider = Provider.of(context,listen: false); - log('i am initstate'); - await notificationsProvider.getUnreadCount(); - } - @override Widget build(BuildContext context) { return AppBar( @@ -273,21 +264,19 @@ class _AppBarWidgetState extends State with TickerProviderStateMix }, ), ], - // Notification icon with unread count badge - Consumer( - builder: (context, notificationsProvider, child) { - final unreadCount = notificationsProvider.totalNotificationUnread; - return CustomBadge( - width: 20, - height: 20, - positionT: -10, - value: unreadCount, - child: ("dashboard/notification").toSvgAsset(height: 24, width: 24, color: AppColor.icon2Color(context)).paddingOnly(top: 0, end: 0), - ).onPress(() { - Navigator.of(context).pushNamed(NotificationsPage.id); - }); - }, - ), + Selector( + selector: (_, myModel) => myModel.totalNotificationUnread, // Selects only the userName + builder: (_, totalNotificationUnread, __) { + return CustomBadge( + width: 16, + height: 16, + positionT: -10, + value: totalNotificationUnread, + child: ("dashboard/notification").toSvgAsset(height: 24, width: 24, color: AppColor.icon2Color(context)).paddingOnly(top: 0, end: 0), + ).onPress(() { + Navigator.of(context).pushNamed(NotificationsPage.id); + }); + }).paddingOnly(end: 8, start: 4), ], ), ), diff --git a/lib/views/pages/user/notifications/notifications_page.dart b/lib/views/pages/user/notifications/notifications_page.dart index d2510879..7770164e 100644 --- a/lib/views/pages/user/notifications/notifications_page.dart +++ b/lib/views/pages/user/notifications/notifications_page.dart @@ -70,16 +70,8 @@ class _NotificationsPageState extends State with TickerProvid _activeFilters!.isAscending = isAscending; _activeFilters!.isRead = _selectedTabIndex; // 0 = All, 1 = Unread, 2 = Read - // Reset and fetch fresh data with filters notificationsProvider.reset(); - await notificationsProvider.getSystemNotifications( - user: userProvider.user!, - resetProvider: true, - filters: _activeFilters, - ); - - // Refresh the unread count after loading notifications - // This updates the badge on the app bar + await notificationsProvider.getSystemNotifications(user: userProvider.user!, resetProvider: true, filters: _activeFilters); await notificationsProvider.getUnreadCount(); }