You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/core/viewModels/notifications_view_model.dart

49 lines
2.4 KiB
Dart

import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_request_model.dart';
import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_response_model.dart';
import 'package:diplomaticquarterapp/core/model/notifications/mark_message_as_read_request_model.dart';
import 'package:diplomaticquarterapp/core/service/notifications_service.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../locator.dart';
import 'base_view_model.dart';
class NotificationViewModel extends BaseViewModel {
NotificationService _notificationService = locator<NotificationService>();
ToDoCountProviderModel model = Provider.of<ToDoCountProviderModel>(AppGlobal.context);
List<GetNotificationsResponseModel> get notifications => _notificationService.notificationsList;
Future getNotifications(GetNotificationsRequestModel getNotificationsRequestModel, BuildContext context) async {
if (getNotificationsRequestModel.currentPage == 0) setState(ViewState.Busy);
await _notificationService.getAllNotifications(getNotificationsRequestModel);
if (_notificationService.hasError) {
error = _notificationService.error;
setState(ViewState.Error);
} else {
setState(ViewState.Idle);
}
}
Future markAsRead(id) async {
// setState(ViewState.Busy);
MarkMessageAsReadRequestModel markMessageAsReadRequestModel = new MarkMessageAsReadRequestModel(notificationPoolID: id);
final authService = new AuthProvider();
await _notificationService.markAsRead(markMessageAsReadRequestModel);
await authService.getDashboard().then((value) {
var notificationCount = '';
notificationCount = value['List_PatientDashboard'][0]['UnreadPatientNotificationCount'] > 99 ? '99+' : value['List_PatientDashboard'][0]['UnreadPatientNotificationCount'].toString();
model.setState(model.count, true, notificationCount);
sharedPref.setString(NOTIFICATION_COUNT, notificationCount);
});
setState(ViewState.Idle);
}
}