From 43e9098d8d46b074ccc2c3f74e1b9cf170301f8a Mon Sep 17 00:00:00 2001 From: Username1548 Date: Mon, 7 Jul 2025 14:16:23 +0700 Subject: [PATCH] added date parsing for reminder --- lib/core/const.dart | 3 +- .../presentation/pages/diary_screen.dart | 7 +-- .../presentation/widgets/calendar_widget.dart | 3 +- .../models/notification_model.dart | 12 +++-- .../notifications_cubit.dart | 6 ++- .../widgets/notification_widget.dart | 51 +++++++++++-------- .../service/notifications_service.dart | 4 +- 7 files changed, 51 insertions(+), 35 deletions(-) diff --git a/lib/core/const.dart b/lib/core/const.dart index 618a9866..4f38a54e 100644 --- a/lib/core/const.dart +++ b/lib/core/const.dart @@ -1,4 +1,5 @@ -String baseUrl = 'https://eatvio.ru'; +// String baseUrl = 'https://eatvio.ru'; +String baseUrl = 'https://dev2.eatvio.com'; const List durationValues = [7, 14, 21]; diff --git a/lib/features/diary/presentation/pages/diary_screen.dart b/lib/features/diary/presentation/pages/diary_screen.dart index fb1987ef..8089c09f 100644 --- a/lib/features/diary/presentation/pages/diary_screen.dart +++ b/lib/features/diary/presentation/pages/diary_screen.dart @@ -24,8 +24,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class DiaryScreen extends StatelessWidget { - const DiaryScreen({super.key}); - + const DiaryScreen({super.key, this.date}); + final DateTime? date; @override Widget build(BuildContext context) { return const DiaryScreenContent(); @@ -52,9 +52,10 @@ class UserDiaryScreen extends StatelessWidget { } class DiaryScreenContent extends StatelessWidget { - const DiaryScreenContent({super.key, this.diaryId, this.currentPlanDay}); + const DiaryScreenContent({super.key, this.diaryId, this.currentPlanDay, this.date}); final int? diaryId; final int? currentPlanDay; + final DateTime? date; @override Widget build(BuildContext context) { final s = S.of(context); diff --git a/lib/features/diary/presentation/widgets/calendar_widget.dart b/lib/features/diary/presentation/widgets/calendar_widget.dart index b0e5c442..83889b22 100644 --- a/lib/features/diary/presentation/widgets/calendar_widget.dart +++ b/lib/features/diary/presentation/widgets/calendar_widget.dart @@ -8,8 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:table_calendar/table_calendar.dart'; class CalendarWidget extends StatefulWidget { - const CalendarWidget({super.key}); - + const CalendarWidget({super.key,}); @override State createState() => _CalendarWidgetState(); } diff --git a/lib/features/notifications/models/notification_model.dart b/lib/features/notifications/models/notification_model.dart index e8489a5a..f9f5d5c2 100644 --- a/lib/features/notifications/models/notification_model.dart +++ b/lib/features/notifications/models/notification_model.dart @@ -106,12 +106,16 @@ class DiaryReminderNotification implements BaseNotificationModel { final NotificationType type; @override final bool isRead; - - - DiaryReminderNotification({required this.type, required this.isRead}); + final DateTime date; + + DiaryReminderNotification({ + required this.type, + required this.isRead, + required this.date, + }); factory DiaryReminderNotification.fromJson(Map json, NotificationType type, {bool? isRead}) { - return DiaryReminderNotification(type: type, isRead: isRead ?? false); + return DiaryReminderNotification(type: type, isRead: isRead ?? false, date: parseDate(json['date'])); } } diff --git a/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart b/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart index b7822d46..9c85f97b 100644 --- a/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart +++ b/lib/features/notifications/presentation/notifications_cubit/notifications_cubit.dart @@ -21,7 +21,8 @@ class NotificationsCubit extends Cubit { Future connectToWebSocket() async { await _newNotificationsSubscription?.cancel(); _newNotificationsSubscription = wsManager.newNotificationsStream?.listen((event) { - _handleNotification(event.data); + + _handleNotification(event.data, event.rootObject['created_at']); }); } @@ -49,8 +50,9 @@ class NotificationsCubit extends Cubit { } } - void _handleNotification(String notificationData) { + void _handleNotification(String notificationData, String createdAt) { final json = jsonDecode(notificationData) as Map; + json.addAll({'date': createdAt}); final stringifiedType = json['notification_class_name']; final type = NotificationType.getTypeFromString(stringifiedType); final notification = _parseNotification(json, type); diff --git a/lib/features/notifications/presentation/widgets/notification_widget.dart b/lib/features/notifications/presentation/widgets/notification_widget.dart index 4ff0faff..ed9d8776 100644 --- a/lib/features/notifications/presentation/widgets/notification_widget.dart +++ b/lib/features/notifications/presentation/widgets/notification_widget.dart @@ -27,7 +27,7 @@ class NotificationWidget extends StatelessWidget { notification: notification as ChosenPlanTomorrowReminderToClientNotification, ), DiaryReminderNotification() => _DiaryReminderWidget( - notification: notification as DiaryReminderNotification, + notification: notification as DiaryReminderNotification, ), ConsultantLeftCommentNotification() => _ConsultantLeftCommentWidget( notification: notification as ConsultantLeftCommentNotification, @@ -121,6 +121,9 @@ class _DiaryReminderWidget extends StatelessWidget { Widget build(BuildContext context) { final s = S.of(context); return _BaseNotificationWidget( + onTap: () { + GoRouter.of(context).go('/diary'); + }, isRead: notification.isRead, notificationsText: s.fillYasterday, ); @@ -252,32 +255,36 @@ class _ChosenPlanFinishedToConsultantWidget extends StatelessWidget { // CardSettingsScreen class _BaseNotificationWidget extends StatelessWidget { - const _BaseNotificationWidget({required this.notificationsText, required this.isRead}); + const _BaseNotificationWidget({required this.notificationsText, required this.isRead, this.onTap}); final String notificationsText; final bool isRead; + final Function()? onTap; @override Widget build(BuildContext context) { - return Row( - children: [ - SizedBox( - width: MediaQuery.sizeOf(context).width * 0.6, - child: Text( - notificationsText, - style: TextStyles.textMMedium.copyWith(color: appTheme.black), - ), - ), - if (!isRead) ...[ - const Spacer(), - Container( - decoration: BoxDecoration( - color: appTheme.blueA400, - shape: BoxShape.circle, + return GestureDetector( + onTap: onTap, + child: Row( + children: [ + SizedBox( + width: MediaQuery.sizeOf(context).width * 0.6, + child: Text( + notificationsText, + style: TextStyles.textMMedium.copyWith(color: appTheme.black), ), - width: 8, - height: 8, - ) - ] - ], + ), + if (!isRead) ...[ + const Spacer(), + Container( + decoration: BoxDecoration( + color: appTheme.blueA400, + shape: BoxShape.circle, + ), + width: 8, + height: 8, + ) + ] + ], + ), ); } } diff --git a/lib/features/notifications/service/notifications_service.dart b/lib/features/notifications/service/notifications_service.dart index 860aab55..3f681eac 100644 --- a/lib/features/notifications/service/notifications_service.dart +++ b/lib/features/notifications/service/notifications_service.dart @@ -24,7 +24,9 @@ class NotificationsService { ChosenPlanStartedToClientNotification.fromJson(notificationJson['data'], type, isRead: readDate != null), NotificationType.chosenPlanTomorrowReminderToClientNotification => ChosenPlanTomorrowReminderToClientNotification.fromJson(notificationJson['data'], type, isRead: readDate != null), - NotificationType.diaryReminderNotification => DiaryReminderNotification.fromJson(notificationJson['data'], type, isRead: readDate != null), + NotificationType.diaryReminderNotification => DiaryReminderNotification.fromJson( + (notificationJson['data'] as Map).putIfAbsent('date', () => notificationJson['created_at']), type, + isRead: readDate != null), NotificationType.consultantLeftComment => ConsultantLeftCommentNotification.fromJson(notificationJson['data'], type, isRead: readDate != null), NotificationType.personalizedDietIsDefined => PersonalizedDietIsDefinedNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),