diff --git a/lib/pages/DrawerPages/notifications/notification_details_page.dart b/lib/pages/DrawerPages/notifications/notification_details_page.dart index 78115746..2b86ed7a 100644 --- a/lib/pages/DrawerPages/notifications/notification_details_page.dart +++ b/lib/pages/DrawerPages/notifications/notification_details_page.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:hmg_patient_app/core/model/notifications/get_notifications_response_model.dart'; +import 'package:hmg_patient_app/core/viewModels/notifications_view_model.dart'; import 'package:hmg_patient_app/core/viewModels/project_view_model.dart'; import 'package:hmg_patient_app/theme/colors.dart'; import 'package:hmg_patient_app/uitl/date_uitl.dart'; @@ -68,6 +69,8 @@ class _NotificationsDetailsPageState extends State { @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); + NotificationViewModel notificationViewModel = Provider.of(context); + notificationViewModel.markAsRead(widget.notification.id); return AppScaffold( isShowAppBar: true, showNewAppBar: true, diff --git a/lib/pages/DrawerPages/notifications/notifications_page.dart b/lib/pages/DrawerPages/notifications/notifications_page.dart index 86c6466b..85ac31c4 100644 --- a/lib/pages/DrawerPages/notifications/notifications_page.dart +++ b/lib/pages/DrawerPages/notifications/notifications_page.dart @@ -15,18 +15,34 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; // ignore: must_be_immutable -class NotificationsPage extends StatelessWidget { +class NotificationsPage extends StatefulWidget { + @override + State createState() => _NotificationsPageState(); +} + +class _NotificationsPageState extends State { int currentIndex = 0; + @override + void didChangeDependencies() { + super.didChangeDependencies(); + // This will be called when navigating back to this page + WidgetsBinding.instance.addPostFrameCallback((_) { + final model = Provider.of(context, listen: false); + currentIndex = 0; // Reset to first page + _loadNotifications(model, context); + }); + } + @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); AppGlobal.context = context; return BaseView( onModelReady: (model) { - GetNotificationsRequestModel getNotificationsRequestModel = new GetNotificationsRequestModel(currentPage: currentIndex, pagingSize: 14, notificationStatusID: 2); - - model.getNotifications(getNotificationsRequestModel, context); + // GetNotificationsRequestModel getNotificationsRequestModel = new GetNotificationsRequestModel(currentPage: currentIndex, pagingSize: 14, notificationStatusID: 2); + // model.getNotifications(getNotificationsRequestModel, context); + _loadNotifications(model, context); }, builder: (_, model, widget) => AppScaffold( isShowAppBar: true, @@ -153,4 +169,15 @@ class NotificationsPage extends StatelessWidget { ), ); } + + void _loadNotifications(NotificationViewModel model, BuildContext context) { + GetNotificationsRequestModel getNotificationsRequestModel = + GetNotificationsRequestModel( + currentPage: currentIndex, + pagingSize: 14, + notificationStatusID: 2, + ); + model.getNotifications(getNotificationsRequestModel, context); + } + }