import 'package:aioa_mobile/core/auth/authenticated_http_client.dart'; import 'package:aioa_mobile/core/config/runtime_config.dart'; import 'package:aioa_mobile/features/tasks/data/notification_repository.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; final notificationRepositoryProvider = Provider( (ref) => NotificationRepository( client: ref.watch(authenticatedHttpClientProvider), baseUrl: RuntimeConfig.apiBaseUrl, ), ); final notificationProvider = AsyncNotifierProvider>( NotificationController.new, ); class NotificationController extends AsyncNotifier> { @override Future> build() => ref.read(notificationRepositoryProvider).list(); Future refresh() async { state = const AsyncLoading(); state = await AsyncValue.guard( () => ref.read(notificationRepositoryProvider).list(), ); } Future markRead(String id) async { final current = state.value; if (current == null) return; final updated = await ref.read(notificationRepositoryProvider).markRead(id); state = AsyncData([ for (final item in current) if (item.id == id) updated else item, ]); } }