43 lines
1.8 KiB
Dart
43 lines
1.8 KiB
Dart
/// 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();
|
|
});
|