import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; import '../../../app/app.locator.dart'; import '../../../models/in_app_notification.dart'; import '../../../services/in_app_notification_service.dart'; import '../../../services/localization_service.dart'; import '../../../services/status_checker_service.dart'; import '../../common/enmus.dart'; class NotificationViewModel extends ReactiveViewModel { // Dependency injection final _statusChecker = locator(); final _navigationService = locator(); final _localizationService = locator(); final _inAppNotificationService = locator(); @override List get listenableServices => [_localizationService, _inAppNotificationService]; // Languages Map get _selectedLanguage => _localizationService.selectedLanguage; Map get selectedLanguage => _selectedLanguage; // Notifications List get _notifications => _inAppNotificationService.notifications; List get notifications => _notifications; // Notification count int get _unreadCount => _inAppNotificationService.unreadCount; int get unreadCount => _unreadCount; // Navigation void pop() => _navigationService.back(); // Remote api call // Notifications Future getAllNotifications() async => await runBusyFuture(_getAllNotifications(), busyObject: StateObjects.notifications); Future _getAllNotifications() async { if (await _statusChecker.checkConnection()) { await _inAppNotificationService.getAllNotifications(); } } Future getUnreadNotifications() async => await runBusyFuture(_getUnreadNotifications()); Future _getUnreadNotifications() async { if (await _statusChecker.checkConnection()) { await _inAppNotificationService.getUnreadNotifications(); } } Future markNotificationsRead() async { if (await _statusChecker.checkConnection()) { await _inAppNotificationService.markNotificationRead(); } } }