diff --git a/lib/core/service/notifications_service.dart b/lib/core/service/notifications_service.dart index 87081a0f..f2cac55e 100644 --- a/lib/core/service/notifications_service.dart +++ b/lib/core/service/notifications_service.dart @@ -35,5 +35,6 @@ class NotificationService extends BaseService { updateNotification(id) { int index = notificationsList.indexWhere((element) => element.id == id); notificationsList[index].isRead = true; + } } diff --git a/lib/core/viewModels/notifications_view_model.dart b/lib/core/viewModels/notifications_view_model.dart index d1bbeda4..ac09e3b2 100644 --- a/lib/core/viewModels/notifications_view_model.dart +++ b/lib/core/viewModels/notifications_view_model.dart @@ -3,6 +3,8 @@ import 'package:diplomaticquarterapp/core/model/notifications/get_notifications_ 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/uitl/gif_loader_dialog_utils.dart'; +import 'package:flutter/material.dart'; import '../../locator.dart'; import 'base_view_model.dart'; @@ -14,15 +16,18 @@ class NotificationViewModel extends BaseViewModel { _notificationService.notificationsList; Future getNotifications( - GetNotificationsRequestModel getNotificationsRequestModel) async { - setState(ViewState.Busy); + 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); + setState(ViewState.Error); + } else { + setState(ViewState.Idle); + } } Future markAsRead(id) async { @@ -30,10 +35,6 @@ class NotificationViewModel extends BaseViewModel { MarkMessageAsReadRequestModel markMessageAsReadRequestModel = new MarkMessageAsReadRequestModel(notificationPoolID: id); await _notificationService.markAsRead(markMessageAsReadRequestModel); - // if (_notificationService.hasError) { - // error = _notificationService.error; - // setState(ViewState.Error); - // } else - // setState(ViewState.Idle); + setState(ViewState.Idle); } } \ No newline at end of file diff --git a/lib/pages/DrawerPages/notifications/notifications_page.dart b/lib/pages/DrawerPages/notifications/notifications_page.dart index 4790eb17..53aad843 100644 --- a/lib/pages/DrawerPages/notifications/notifications_page.dart +++ b/lib/pages/DrawerPages/notifications/notifications_page.dart @@ -3,6 +3,7 @@ import 'package:diplomaticquarterapp/core/viewModels/notifications_view_model.da import 'package:diplomaticquarterapp/pages/DrawerPages/notifications/notification_details_page.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; +import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; @@ -45,7 +46,7 @@ class NotificationsPage extends StatelessWidget { pagingSize: 14, notificationStatusID: 2); - model.getNotifications(getNotificationsRequestModel); + model.getNotifications(getNotificationsRequestModel, context); }, builder: (_, model, widget) => AppScaffold( isShowAppBar: true, @@ -57,7 +58,7 @@ class NotificationsPage extends StatelessWidget { (notification) => InkWell( onTap: () async { if(!notification.isRead) - await model.markAsRead(notification.id); + model.markAsRead(notification.id); Navigator.push( context, MaterialPageRoute( @@ -120,7 +121,9 @@ class NotificationsPage extends StatelessWidget { .toList() ..add( InkWell( - onTap: () { + onTap: () async { + GifLoaderDialogUtils.showMyDialog( + context); currentIndex++; GetNotificationsRequestModel getNotificationsRequestModel = @@ -129,7 +132,10 @@ class NotificationsPage extends StatelessWidget { pagingSize: 14, notificationStatusID: 2); - model.getNotifications(getNotificationsRequestModel); + await model.getNotifications(getNotificationsRequestModel,context); + GifLoaderDialogUtils.hideDialog( + context); + }, child: Center( child: Image.asset('assets/images/notf.png'),