Compare commits

..

No commits in common. 'df100249754cf3083a849fb4665dd98b99748fac' and '2a20b92c336271c5c9d9bdd669238ec2dcba211f' have entirely different histories.

@ -247,7 +247,6 @@ class URLs {
static get getNotificationInbox => "$_baseUrl/NotificationNew/Inbox"; // get notifications with filters static get getNotificationInbox => "$_baseUrl/NotificationNew/Inbox"; // get notifications with filters
static get markAllNotificationsAsRead => "$_baseUrl/NotificationNew/MarkAllRead"; // mark all as read static get markAllNotificationsAsRead => "$_baseUrl/NotificationNew/MarkAllRead"; // mark all as read
static get markOneNotificationAsRead => "$_baseUrl/NotificationNew/MarkAsReadOneNotification"; // mark one notification as read static get markOneNotificationAsRead => "$_baseUrl/NotificationNew/MarkAsReadOneNotification"; // mark one notification as read
static get getUnreadNotificationCount => "$_baseUrl/NotificationNew/GetUnread"; // mark one notification as read
// Notification Filter Lookups // Notification Filter Lookups
static get getNotificationPriorityLookup => "$_baseUrl/Lookups/GetLookup?lookupEnum=5021"; // notification priority filter static get getNotificationPriorityLookup => "$_baseUrl/Lookups/GetLookup?lookupEnum=5021"; // notification priority filter

@ -6,9 +6,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_api_availability/google_api_availability.dart'; import 'package:google_api_availability/google_api_availability.dart';
import 'package:huawei_push/huawei_push.dart' as h_push; import 'package:huawei_push/huawei_push.dart' as h_push;
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/notification/notification_manger.dart'; import 'package:test_sa/controllers/notification/notification_manger.dart';
import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
import 'package:test_sa/models/device/device_transfer.dart'; import 'package:test_sa/models/device/device_transfer.dart';
import 'package:test_sa/models/new_models/gas_refill_model.dart'; import 'package:test_sa/models/new_models/gas_refill_model.dart';
import 'package:test_sa/modules/cm_module/cm_detail_page.dart'; import 'package:test_sa/modules/cm_module/cm_detail_page.dart';
@ -265,14 +263,6 @@ class FirebaseNotificationManger {
hashcode: DateTime.now().millisecondsSinceEpoch.hashCode, hashcode: DateTime.now().millisecondsSinceEpoch.hashCode,
payload: json.encode(message.data), payload: json.encode(message.data),
context: context); context: context);
// Update unread notification count badge when new notification arrives
try {
final notificationsProvider = Provider.of<NotificationsProvider>(context, listen: false);
notificationsProvider.getUnreadCount();
} catch (e) {
log('Error updating notification count: $e');
}
} }
} }
return; return;

@ -1,5 +1,4 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:developer';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
@ -121,6 +120,8 @@ class NotificationsProvider extends ChangeNotifier {
} }
} }
/// Mark all notifications as read
/// Returns a map with success status and message from API
Future<Map<String, dynamic>> markAllAsRead({required String userId}) async { Future<Map<String, dynamic>> markAllAsRead({required String userId}) async {
try { try {
final Map<String, dynamic> body = {"userId": userId}; final Map<String, dynamic> body = {"userId": userId};
@ -158,6 +159,8 @@ class NotificationsProvider extends ChangeNotifier {
} }
} }
/// Mark one notification as read
/// Returns true if successful, false otherwise
Future<bool> markOneAsRead({required String notificationId}) async { Future<bool> markOneAsRead({required String notificationId}) async {
try { try {
final response = await ApiManager.instance.get("${URLs.markOneNotificationAsRead}?NotificationId=$notificationId", enableToastMessage: false); final response = await ApiManager.instance.get("${URLs.markOneNotificationAsRead}?NotificationId=$notificationId", enableToastMessage: false);
@ -185,53 +188,11 @@ class NotificationsProvider extends ChangeNotifier {
} }
} }
Future<int?> getUnreadCount() async { /// return -2 if request in progress
int? count; /// return -1 if error happen when sending request
try { /// return state code if request complete may be 200, 404 or 403
final response = await ApiManager.instance.get(URLs.getUnreadNotificationCount, enableToastMessage: false); /// for more details check http state manager
if (response.statusCode >= 200 && response.statusCode < 300) { /// lib\controllers\http_status_manger\http_status_manger.dart
final responseData = json.decode(response.body);
log('count response :: $responseData');
count = responseData['data'];
// Update the totalNotificationUnread property
totalNotificationUnread = count ?? 0;
notifyListeners();
}
return count;
} catch (error) {
print('Error getting unread notification count: $error');
return count;
}
}
/// Manually reset the unread count to zero
/// Useful when you want to clear the badge without making an API call
void resetUnreadCount() {
totalNotificationUnread = 0;
notifyListeners();
}
/// Update unread count manually (e.g., from push notification)
/// Useful when you receive a notification and want to increment the badge
void updateUnreadCount(int newCount) {
totalNotificationUnread = newCount;
notifyListeners();
}
/// Increment unread count by 1 (e.g., when receiving a new push notification)
void incrementUnreadCount() {
totalNotificationUnread++;
notifyListeners();
}
/// Decrement unread count by 1 (e.g., when marking one as read locally)
void decrementUnreadCount() {
if (totalNotificationUnread > 0) {
totalNotificationUnread--;
notifyListeners();
}
}
Future<List<SystemNotificationModel>?> getRecentNotifications({ Future<List<SystemNotificationModel>?> getRecentNotifications({
required String host, required String host,
required User user, required User user,

@ -1,10 +1,7 @@
import 'dart:developer';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:test_sa/controllers/api_routes/api_manager.dart'; import 'package:test_sa/controllers/api_routes/api_manager.dart';
import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/dashboard_latest/dashboard_provider.dart'; import 'package:test_sa/dashboard_latest/dashboard_provider.dart';
import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/context_extension.dart';
@ -13,7 +10,6 @@ import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/helper/utils.dart'; import 'package:test_sa/helper/utils.dart';
import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/custom_badge.dart';
import 'package:test_sa/views/pages/user/notifications/notifications_page.dart'; import 'package:test_sa/views/pages/user/notifications/notifications_page.dart';
import 'package:test_sa/views/pages/user/notifications/unread_chat_list.dart'; import 'package:test_sa/views/pages/user/notifications/unread_chat_list.dart';
@ -42,8 +38,6 @@ class _AppBarWidgetState extends State<AppBarWidget> with TickerProviderStateMix
super.initState(); super.initState();
// Profile section animation (left to right with fade) // Profile section animation (left to right with fade)
getUnreadCount();
_leftController = AnimationController( _leftController = AnimationController(
duration: const Duration(milliseconds: 600), duration: const Duration(milliseconds: 600),
vsync: this, vsync: this,
@ -101,12 +95,6 @@ class _AppBarWidgetState extends State<AppBarWidget> with TickerProviderStateMix
super.dispose(); super.dispose();
} }
Future<void> getUnreadCount () async{
NotificationsProvider notificationsProvider = Provider.of<NotificationsProvider>(context,listen: false);
log('i am initstate');
await notificationsProvider.getUnreadCount();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppBar( return AppBar(
@ -265,21 +253,9 @@ class _AppBarWidgetState extends State<AppBarWidget> with TickerProviderStateMix
}), }),
16.width, 16.width,
], ],
// Notification icon with unread count badge ("dashboard/notification").toSvgAsset(height: 24, width: 24, color: AppColor.icon2Color(context)).paddingOnly(top: 0, end: 0).onPress(() {
Consumer<NotificationsProvider>(
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); Navigator.of(context).pushNamed(NotificationsPage.id);
}); }),
},
),
], ],
), ),
), ),

@ -424,9 +424,9 @@ class AppColor {
switch (id) { switch (id) {
//low priority //low priority
case 2: case 2:
return greenStatusTextColor; return greenStatusColor;
case 3: case 3:
return blueStatusTextColor; return greenStatusTextColor;
case 0: case 0:
return redStatusTextColor; return redStatusTextColor;
case 1: case 1:
@ -448,7 +448,7 @@ class AppColor {
case 1: case 1:
return redStatusColor; return redStatusColor;
case 3: case 3:
return blueStatusColor; return greenStatusColor;
default: default:
return defaultStatusColor(context); return defaultStatusColor(context);
} }

@ -36,7 +36,7 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
int _selectedTabIndex = 0; // 0: All, 1: Unread, 2: Read int _selectedTabIndex = 0; // 0: All, 1: Unread, 2: Read
String _searchQuery = ''; String _searchQuery = '';
bool isAscending = true; bool isAscending = false;
NotificationFilterModel? _activeFilters; NotificationFilterModel? _activeFilters;
Timer? _debounceTimer; Timer? _debounceTimer;
@ -77,10 +77,6 @@ class _NotificationsPageState extends State<NotificationsPage> with TickerProvid
resetProvider: true, resetProvider: true,
filters: _activeFilters, filters: _activeFilters,
); );
// Refresh the unread count after loading notifications
// This updates the badge on the app bar
await notificationsProvider.getUnreadCount();
} }
void _onSearchChanged(String value) { void _onSearchChanged(String value) {

Loading…
Cancel
Save