This commit is contained in:
Phuoc Nguyen
2025-11-03 15:02:33 +07:00
parent 56c470baa1
commit aa3a52bba7
17 changed files with 1393 additions and 345 deletions

View File

@@ -0,0 +1,42 @@
/// Notifications Providers
///
/// Riverpod providers for managing notification state.
library;
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:worker/features/notifications/data/datasources/notification_local_datasource.dart';
import 'package:worker/features/notifications/data/repositories/notification_repository_impl.dart';
import 'package:worker/features/notifications/domain/entities/notification.dart';
import 'package:worker/features/notifications/domain/repositories/notification_repository.dart';
/// Notification Local Data Source Provider
final notificationLocalDataSourceProvider =
Provider<NotificationLocalDataSource>((ref) {
return NotificationLocalDataSource();
});
/// Notification Repository Provider
final notificationRepositoryProvider = Provider<NotificationRepository>((ref) {
final localDataSource = ref.watch(notificationLocalDataSourceProvider);
return NotificationRepositoryImpl(localDataSource: localDataSource);
});
/// All Notifications Provider
final notificationsProvider = FutureProvider<List<Notification>>((ref) async {
final repository = ref.watch(notificationRepositoryProvider);
return await repository.getAllNotifications();
});
/// Filtered Notifications Provider (by category parameter)
/// Use .family to pass category as parameter from UI
final filteredNotificationsProvider =
FutureProvider.family<List<Notification>, String>((ref, category) async {
final repository = ref.watch(notificationRepositoryProvider);
return await repository.getNotificationsByCategory(category);
});
/// Unread Count Provider
final unreadNotificationCountProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(notificationRepositoryProvider);
return await repository.getUnreadCount();
});