Merge pull request 'feat(notifications): unread notifications handling' (#467) from misha/eatvio_app:notifications into main

Reviewed-on: eatvio/eatvio_app#467
This commit is contained in:
mso7nueh
2025-05-28 13:10:47 +00:00
12 changed files with 254 additions and 85 deletions

View File

@@ -26,6 +26,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference
@@ -43,6 +44,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@@ -203,9 +203,10 @@ class _BottomNavigationBarWidgetState extends State<BottomNavigationBarWidget> {
return badges.Badge( return badges.Badge(
position: badges.BadgePosition.topEnd(), position: badges.BadgePosition.topEnd(),
badgeAnimation: const badges.BadgeAnimation.fade(), badgeAnimation: const badges.BadgeAnimation.fade(),
badgeContent: Text( showBadge: state is NotificationsStateLoaded && state.hasUnreadNotifications,
(state is NotificationsStateLoaded) ? state.notificationsCount.toString() : '0', badgeContent: const Text(
style: const TextStyle( '',
style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 8, fontSize: 8,
), ),

View File

@@ -1,10 +1,13 @@
sealed class BaseNotificationModel { sealed class BaseNotificationModel {
abstract final NotificationType type; abstract final NotificationType type;
abstract final bool isRead;
} }
class PlanSubscriptionStartedToAuthorNotification implements BaseNotificationModel { class PlanSubscriptionStartedToAuthorNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final String customerName; final String customerName;
final String chatId; final String chatId;
@@ -14,14 +17,16 @@ class PlanSubscriptionStartedToAuthorNotification implements BaseNotificationMod
required this.planName, required this.planName,
required this.customerName, required this.customerName,
required this.chatId, required this.chatId,
required this.isRead,
}); });
factory PlanSubscriptionStartedToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory PlanSubscriptionStartedToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return PlanSubscriptionStartedToAuthorNotification( return PlanSubscriptionStartedToAuthorNotification(
type: type, type: type,
planName: json['plan_name'], planName: json['plan_name'],
customerName: json['user_name'], customerName: json['user_name'],
chatId: json['chat_id'], chatId: json['chat_id'],
isRead: isRead ?? false,
); );
} }
} }
@@ -29,6 +34,8 @@ class PlanSubscriptionStartedToAuthorNotification implements BaseNotificationMod
class PlanSubscriptionCanceledToAuthorNotification implements BaseNotificationModel { class PlanSubscriptionCanceledToAuthorNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final String customerName; final String customerName;
@@ -36,13 +43,15 @@ class PlanSubscriptionCanceledToAuthorNotification implements BaseNotificationMo
required this.type, required this.type,
required this.planName, required this.planName,
required this.customerName, required this.customerName,
required this.isRead,
}); });
factory PlanSubscriptionCanceledToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory PlanSubscriptionCanceledToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return PlanSubscriptionCanceledToAuthorNotification( return PlanSubscriptionCanceledToAuthorNotification(
type: type, type: type,
planName: json['plan_name'], planName: json['plan_name'],
customerName: json['user_name'], customerName: json['user_name'],
isRead: isRead ?? false,
); );
} }
} }
@@ -50,6 +59,8 @@ class PlanSubscriptionCanceledToAuthorNotification implements BaseNotificationMo
class ChosenPlanStartedToClientNotification implements BaseNotificationModel { class ChosenPlanStartedToClientNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final int planId; final int planId;
@@ -57,13 +68,15 @@ class ChosenPlanStartedToClientNotification implements BaseNotificationModel {
required this.type, required this.type,
required this.planName, required this.planName,
required this.planId, required this.planId,
required this.isRead,
}); });
factory ChosenPlanStartedToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ChosenPlanStartedToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ChosenPlanStartedToClientNotification( return ChosenPlanStartedToClientNotification(
type: type, type: type,
planName: json['plan_name'], planName: json['plan_name'],
planId: json['plan_id'], planId: json['plan_id'],
isRead: isRead ?? false,
); );
} }
} }
@@ -71,58 +84,70 @@ class ChosenPlanStartedToClientNotification implements BaseNotificationModel {
class ChosenPlanTomorrowReminderToClientNotification implements BaseNotificationModel { class ChosenPlanTomorrowReminderToClientNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
ChosenPlanTomorrowReminderToClientNotification({ ChosenPlanTomorrowReminderToClientNotification({
required this.type, required this.type,
required this.planName, required this.planName,
required this.isRead,
}); });
factory ChosenPlanTomorrowReminderToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ChosenPlanTomorrowReminderToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ChosenPlanTomorrowReminderToClientNotification( return ChosenPlanTomorrowReminderToClientNotification(type: type, planName: json['plan_name'], isRead: isRead ?? false);
type: type,
planName: json['plan_name'],
);
} }
} }
class DiaryReminderNotification implements BaseNotificationModel { class DiaryReminderNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
DiaryReminderNotification({required this.type, required this.isRead});
DiaryReminderNotification({required this.type}); factory DiaryReminderNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return DiaryReminderNotification(type: type, isRead: isRead ?? false);
factory DiaryReminderNotification.fromJson(Map<String, dynamic> json, NotificationType type) {
return DiaryReminderNotification(
type: type,
);
} }
} }
class ConsultantLeftCommentNotification implements BaseNotificationModel { class ConsultantLeftCommentNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final DateTime date; final DateTime date;
ConsultantLeftCommentNotification({ ConsultantLeftCommentNotification({
required this.type, required this.type,
required this.date, required this.date,
required this.isRead,
}); });
factory ConsultantLeftCommentNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ConsultantLeftCommentNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ConsultantLeftCommentNotification(type: type, date: json['diary_date']); return ConsultantLeftCommentNotification(
type: type,
date: json['diary_date'],
isRead: isRead ?? false,
);
} }
} }
class PersonalizedDietIsDefinedNotification implements BaseNotificationModel { class PersonalizedDietIsDefinedNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
PersonalizedDietIsDefinedNotification({required this.type}); PersonalizedDietIsDefinedNotification({
required this.type,
required this.isRead,
});
factory PersonalizedDietIsDefinedNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory PersonalizedDietIsDefinedNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return PersonalizedDietIsDefinedNotification( return PersonalizedDietIsDefinedNotification(
type: type, type: type,
isRead: isRead ?? false,
); );
} }
} }
@@ -130,30 +155,41 @@ class PersonalizedDietIsDefinedNotification implements BaseNotificationModel {
class ChosenPlanFinishedToClientNotification implements BaseNotificationModel { class ChosenPlanFinishedToClientNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
ChosenPlanFinishedToClientNotification({ ChosenPlanFinishedToClientNotification({
required this.type, required this.type,
required this.planName, required this.planName,
required this.isRead,
}); });
factory ChosenPlanFinishedToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ChosenPlanFinishedToClientNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ChosenPlanFinishedToClientNotification(type: type, planName: json['plan_name']); return ChosenPlanFinishedToClientNotification(
type: type,
planName: json['plan_name'],
isRead: isRead ?? false,
);
} }
} }
class PlanSubscriptionCanceledToCustomerNotification implements BaseNotificationModel { class PlanSubscriptionCanceledToCustomerNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
PlanSubscriptionCanceledToCustomerNotification({ PlanSubscriptionCanceledToCustomerNotification({
required this.type, required this.type,
required this.planName, required this.planName,
required this.isRead,
}); });
factory PlanSubscriptionCanceledToCustomerNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory PlanSubscriptionCanceledToCustomerNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return PlanSubscriptionCanceledToCustomerNotification( return PlanSubscriptionCanceledToCustomerNotification(
type: type, type: type,
planName: json['plan_name'], planName: json['plan_name'],
isRead: isRead ?? false,
); );
} }
} }
@@ -161,17 +197,21 @@ class PlanSubscriptionCanceledToCustomerNotification implements BaseNotification
class ChosenPlanStartedToConsultantNotification implements BaseNotificationModel { class ChosenPlanStartedToConsultantNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final String customerName; final String customerName;
ChosenPlanStartedToConsultantNotification({ ChosenPlanStartedToConsultantNotification({
required this.type, required this.type,
required this.isRead,
required this.planName, required this.planName,
required this.customerName, required this.customerName,
}); });
factory ChosenPlanStartedToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ChosenPlanStartedToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ChosenPlanStartedToConsultantNotification( return ChosenPlanStartedToConsultantNotification(
type: type, type: type,
isRead: isRead ?? false,
planName: json['plan_name'], planName: json['plan_name'],
customerName: json['client_name'], customerName: json['client_name'],
); );
@@ -181,19 +221,23 @@ class ChosenPlanStartedToConsultantNotification implements BaseNotificationModel
class ChosenPlanTomorrowReminderToConsultantNotification implements BaseNotificationModel { class ChosenPlanTomorrowReminderToConsultantNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final String customerName; final String customerName;
ChosenPlanTomorrowReminderToConsultantNotification({ ChosenPlanTomorrowReminderToConsultantNotification({
required this.type, required this.type,
required this.planName, required this.planName,
required this.customerName, required this.customerName,
required this.isRead,
}); });
factory ChosenPlanTomorrowReminderToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ChosenPlanTomorrowReminderToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ChosenPlanTomorrowReminderToConsultantNotification( return ChosenPlanTomorrowReminderToConsultantNotification(
type: type, type: type,
planName: json['plan_name'], planName: json['plan_name'],
customerName: json['client_name'], customerName: json['client_name'],
isRead: isRead ?? false,
); );
} }
} }
@@ -201,17 +245,21 @@ class ChosenPlanTomorrowReminderToConsultantNotification implements BaseNotifica
class PlanSubscriptionPaidToAuthorNotification implements BaseNotificationModel { class PlanSubscriptionPaidToAuthorNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final String customerName; final String customerName;
PlanSubscriptionPaidToAuthorNotification({ PlanSubscriptionPaidToAuthorNotification({
required this.type, required this.type,
required this.isRead,
required this.planName, required this.planName,
required this.customerName, required this.customerName,
}); });
factory PlanSubscriptionPaidToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory PlanSubscriptionPaidToAuthorNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return PlanSubscriptionPaidToAuthorNotification( return PlanSubscriptionPaidToAuthorNotification(
type: type, type: type,
isRead: isRead ?? false,
planName: json['plan_name'], planName: json['plan_name'],
customerName: json['user_name'], customerName: json['user_name'],
); );
@@ -221,6 +269,8 @@ class PlanSubscriptionPaidToAuthorNotification implements BaseNotificationModel
class ChosenPlanFinishedToConsultantNotification implements BaseNotificationModel { class ChosenPlanFinishedToConsultantNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
final String planName; final String planName;
final String customerName; final String customerName;
final int planId; final int planId;
@@ -229,14 +279,16 @@ class ChosenPlanFinishedToConsultantNotification implements BaseNotificationMode
required this.planName, required this.planName,
required this.customerName, required this.customerName,
required this.planId, required this.planId,
required this.isRead,
}); });
factory ChosenPlanFinishedToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type) { factory ChosenPlanFinishedToConsultantNotification.fromJson(Map<String, dynamic> json, NotificationType type, {bool? isRead}) {
return ChosenPlanFinishedToConsultantNotification( return ChosenPlanFinishedToConsultantNotification(
type: type, type: type,
planName: json['plan_name'], planName: json['plan_name'],
customerName: json['client_name'], customerName: json['client_name'],
planId: json['plan_id'], planId: json['plan_id'],
isRead: isRead ?? false,
); );
} }
} }
@@ -244,8 +296,12 @@ class ChosenPlanFinishedToConsultantNotification implements BaseNotificationMode
class UnknownNotification implements BaseNotificationModel { class UnknownNotification implements BaseNotificationModel {
@override @override
final NotificationType type; final NotificationType type;
@override
final bool isRead;
UnknownNotification({ UnknownNotification({
required this.type, required this.type,
this.isRead = true,
}); });
} }

View File

@@ -25,8 +25,7 @@ class NotificationsCubit extends Cubit<NotificationsState> {
NotificationType.planSubscriptionStartedToAuthor => PlanSubscriptionStartedToAuthorNotification.fromJson(notificationJson, type), NotificationType.planSubscriptionStartedToAuthor => PlanSubscriptionStartedToAuthorNotification.fromJson(notificationJson, type),
NotificationType.planSubscriptionCanceledToAuthor => PlanSubscriptionCanceledToAuthorNotification.fromJson(notificationJson, type), NotificationType.planSubscriptionCanceledToAuthor => PlanSubscriptionCanceledToAuthorNotification.fromJson(notificationJson, type),
NotificationType.chosenPlanStartedToClientNotification => ChosenPlanStartedToClientNotification.fromJson(notificationJson, type), NotificationType.chosenPlanStartedToClientNotification => ChosenPlanStartedToClientNotification.fromJson(notificationJson, type),
NotificationType.chosenPlanTomorrowReminderToClientNotification => NotificationType.chosenPlanTomorrowReminderToClientNotification => ChosenPlanTomorrowReminderToClientNotification.fromJson(notificationJson, type),
ChosenPlanTomorrowReminderToClientNotification.fromJson(notificationJson, type),
NotificationType.diaryReminderNotification => DiaryReminderNotification.fromJson(notificationJson, type), NotificationType.diaryReminderNotification => DiaryReminderNotification.fromJson(notificationJson, type),
NotificationType.consultantLeftComment => ConsultantLeftCommentNotification.fromJson(notificationJson, type), NotificationType.consultantLeftComment => ConsultantLeftCommentNotification.fromJson(notificationJson, type),
NotificationType.personalizedDietIsDefined => PersonalizedDietIsDefinedNotification.fromJson(notificationJson, type), NotificationType.personalizedDietIsDefined => PersonalizedDietIsDefinedNotification.fromJson(notificationJson, type),
@@ -54,6 +53,7 @@ class NotificationsCubit extends Cubit<NotificationsState> {
NotificationsState.loaded( NotificationsState.loaded(
notifications: _notifications, notifications: _notifications,
notificationsCount: _notifications.length, notificationsCount: _notifications.length,
hasUnreadNotifications: true,
), ),
); );
} }
@@ -67,10 +67,26 @@ class NotificationsCubit extends Cubit<NotificationsState> {
NotificationsState.loaded( NotificationsState.loaded(
notifications: _notifications, notifications: _notifications,
notificationsCount: _notifications.length, notificationsCount: _notifications.length,
hasUnreadNotifications: (notifications ?? []).where((elem) => elem.isRead == false).isNotEmpty,
), ),
); );
} catch (e, st) { } catch (e, st) {
log(e.toString(), stackTrace: st); log(e.toString(), stackTrace: st);
} }
} }
Future<void> markNotificationsAsRead() async {
final currentState = state;
if (currentState is NotificationsStateLoaded) {
try {
emit(currentState.copyWith(isLoading: true));
await notificationsRepository.markNotificationsAsRead();
await getNotifications();
emit(currentState.copyWith(isLoading: false, hasUnreadNotifications: false));
} catch (e, st) {
log(e.toString(), stackTrace: st);
emit(currentState.copyWith(isLoading: false));
}
}
}
} }

View File

@@ -10,8 +10,10 @@ abstract class NotificationsState with _$NotificationsState {
const factory NotificationsState.empty() = NotificationsStateEmpty; const factory NotificationsState.empty() = NotificationsStateEmpty;
const factory NotificationsState.loaded({ const factory NotificationsState.loaded({
required List<BaseNotificationModel> notifications, required List<BaseNotificationModel> notifications,
required int notificationsCount, required int notificationsCount,
@Default(false) bool isLoading,
@Default(false) bool hasUnreadNotifications,
}) = NotificationsStateLoaded; }) = NotificationsStateLoaded;
const factory NotificationsState.error({ const factory NotificationsState.error({

View File

@@ -1,8 +1,12 @@
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_divider.dart'; import 'package:eatvio_app/core/widgets/custom_divider.dart';
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/core/widgets/loader.dart';
import 'package:eatvio_app/features/notifications/presentation/notifications_cubit/notifications_cubit.dart'; import 'package:eatvio_app/features/notifications/presentation/notifications_cubit/notifications_cubit.dart';
import 'package:eatvio_app/features/notifications/presentation/notifications_cubit/notifications_state.dart'; import 'package:eatvio_app/features/notifications/presentation/notifications_cubit/notifications_state.dart';
import 'package:eatvio_app/features/notifications/presentation/widgets/notification_widget.dart'; import 'package:eatvio_app/features/notifications/presentation/widgets/notification_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
@@ -11,6 +15,7 @@ class NotificationsScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final s = S.of(context);
return BlocBuilder<NotificationsCubit, NotificationsState>( return BlocBuilder<NotificationsCubit, NotificationsState>(
builder: (BuildContext context, NotificationsState state) { builder: (BuildContext context, NotificationsState state) {
return Scaffold( return Scaffold(
@@ -19,38 +24,58 @@ class NotificationsScreen extends StatelessWidget {
title: const Text('Уведомления'), title: const Text('Уведомления'),
), ),
body: state is NotificationsStateLoaded body: state is NotificationsStateLoaded
? Padding( ? Stack(children: [
padding: const EdgeInsets.only(top: 8.0), Padding(
child: Container( padding: const EdgeInsets.only(top: 8.0),
padding: const EdgeInsets.only(top: 16), child: Container(
decoration: BoxDecoration( padding: const EdgeInsets.only(top: 16),
color: appTheme.whiteA700, decoration: BoxDecoration(
borderRadius: const BorderRadius.only( color: appTheme.whiteA700,
topLeft: Radius.circular(12), borderRadius: const BorderRadius.only(
topRight: Radius.circular(12), topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
), ),
), child: state.isLoading
child: CustomScrollView( ? const Center(child: Loader())
slivers: [ : CustomScrollView(
SliverList.separated( slivers: [
separatorBuilder: (context, index) => const Padding( SliverList.separated(
padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16), separatorBuilder: (context, index) => const Padding(
child: CustomDivider(), padding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),
), child: CustomDivider(),
itemBuilder: (context, index) { ),
return Padding( itemBuilder: (context, index) {
padding: const EdgeInsets.symmetric(horizontal: 16), return Padding(
child: NotificationWidget( padding: const EdgeInsets.symmetric(horizontal: 16),
notification: state.notifications[index], child: NotificationWidget(
), notification: state.notifications[index],
); ),
}, );
itemCount: state.notifications.length, },
) itemCount: state.notifications.length,
], )
],
),
), ),
), ),
) Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
child: CustomOutlinedButton(
text: s.markAsRead,
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle:
ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
onPressed: () async {
context.read<NotificationsCubit>().markNotificationsAsRead();
},
),
),
)
])
: const Placeholder(), : const Placeholder(),
); );
}, },

View File

@@ -65,7 +65,8 @@ class _PlanSubscriptionStartedToAuthorWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
notificationsText: s.userSubscribedToPlan(notification.customerName, notification.planName), isRead: notification.isRead,
notificationsText: s.fillYasterday,
); );
} }
} }
@@ -78,7 +79,8 @@ class _PlanSubscriptionCanceledToAuthorWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
notificationsText: s.userCanceldThePlanSubscription(notification.customerName, notification.planName), isRead: notification.isRead,
notificationsText: s.fillYasterday,
); );
} }
} }
@@ -91,7 +93,8 @@ class _ChosenPlanStartedToClientWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
notificationsText: s.planStarted(notification.planName), isRead: notification.isRead,
notificationsText: s.fillYasterday,
); );
} }
} }
@@ -104,7 +107,8 @@ class _ChosenPlanTomorrowReminderToClientWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
notificationsText: s.tomorrowYourPlanWillStart(notification.planName), isRead: notification.isRead,
notificationsText: s.fillYasterday,
); );
} }
} }
@@ -116,6 +120,7 @@ class _DiaryReminderWidget extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: s.fillYasterday, notificationsText: s.fillYasterday,
); );
} }
@@ -129,6 +134,7 @@ class _ConsultantLeftCommentWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: s.consultantLeftComment(notification.date), notificationsText: s.consultantLeftComment(notification.date),
); );
} }
@@ -151,6 +157,7 @@ class _ChosenPlanFinishedToClientWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: '${s.congratsYouHaveFinishedPlan} «${notification.planName}»', notificationsText: '${s.congratsYouHaveFinishedPlan} «${notification.planName}»',
); );
} }
@@ -164,6 +171,7 @@ class _PlanSubscriptionCanceledToCustomerWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: s.youCanceledSubscriptionToPlan(notification.planName), notificationsText: s.youCanceledSubscriptionToPlan(notification.planName),
); );
} }
@@ -177,6 +185,7 @@ class _ChosenPlanStartedToConsultantWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: s.planWithUserStarted(notification.planName, notification.customerName), notificationsText: s.planWithUserStarted(notification.planName, notification.customerName),
); );
} }
@@ -190,6 +199,7 @@ class _ChosenPlanTomorrowReminderToConsultantWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: s.tommorowPlanWithUserWillStart(notification.planName, notification.customerName), notificationsText: s.tommorowPlanWithUserWillStart(notification.planName, notification.customerName),
); );
} }
@@ -203,6 +213,7 @@ class _PlanSubscriptionPaidToAuthorWidget extends StatelessWidget {
final s = S.of(context); final s = S.of(context);
return _BaseNotificationWidget( return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: s.userPaidThePlan(notification.customerName, notification.planName), notificationsText: s.userPaidThePlan(notification.customerName, notification.planName),
); );
} }
@@ -240,16 +251,32 @@ class _ChosenPlanFinishedToConsultantWidget extends StatelessWidget {
// CardSettingsScreen // CardSettingsScreen
class _BaseNotificationWidget extends StatelessWidget { class _BaseNotificationWidget extends StatelessWidget {
const _BaseNotificationWidget({required this.notificationsText}); const _BaseNotificationWidget({required this.notificationsText, required this.isRead});
final String notificationsText; final String notificationsText;
final bool isRead;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return Row(
width: MediaQuery.sizeOf(context).width * 0.6, children: [
child: Text( SizedBox(
notificationsText, width: MediaQuery.sizeOf(context).width * 0.6,
style: TextStyles.textMMedium.copyWith(color: appTheme.black), child: Text(
), notificationsText,
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
),
),
if (!isRead) ...[
const Spacer(),
Container(
decoration: BoxDecoration(
color: appTheme.blueA400,
shape: BoxShape.circle,
),
width: 8,
height: 8,
)
]
],
); );
} }
} }

View File

@@ -12,4 +12,12 @@ class NotificationsRepository {
rethrow; rethrow;
} }
} }
Future<void> markNotificationsAsRead() async {
try {
await notificationsService.markNotificationsAsRead();
} catch (e) {
rethrow;
}
}
} }

View File

@@ -13,23 +13,33 @@ class NotificationsService {
final notifications = data.map((notificationJson) { final notifications = data.map((notificationJson) {
try { try {
final stringifiedType = notificationJson['data']['notification_class_name']; final stringifiedType = notificationJson['data']['notification_class_name'];
final readDate = notificationJson['read_at'];
final type = NotificationType.getTypeFromString(stringifiedType); final type = NotificationType.getTypeFromString(stringifiedType);
return switch (type) { return switch (type) {
NotificationType.planSubscriptionStartedToAuthor => PlanSubscriptionStartedToAuthorNotification.fromJson(notificationJson['data'], type), NotificationType.planSubscriptionStartedToAuthor =>
NotificationType.planSubscriptionCanceledToAuthor => PlanSubscriptionCanceledToAuthorNotification.fromJson(notificationJson['data'], type), PlanSubscriptionStartedToAuthorNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.chosenPlanStartedToClientNotification => ChosenPlanStartedToClientNotification.fromJson(notificationJson['data'], type), NotificationType.planSubscriptionCanceledToAuthor =>
PlanSubscriptionCanceledToAuthorNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.chosenPlanStartedToClientNotification =>
ChosenPlanStartedToClientNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.chosenPlanTomorrowReminderToClientNotification => NotificationType.chosenPlanTomorrowReminderToClientNotification =>
ChosenPlanTomorrowReminderToClientNotification.fromJson(notificationJson['data'], type), ChosenPlanTomorrowReminderToClientNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.diaryReminderNotification => DiaryReminderNotification.fromJson(notificationJson['data'], type), NotificationType.diaryReminderNotification => DiaryReminderNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.consultantLeftComment => ConsultantLeftCommentNotification.fromJson(notificationJson['data'], type), NotificationType.consultantLeftComment => ConsultantLeftCommentNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.personalizedDietIsDefined => PersonalizedDietIsDefinedNotification.fromJson(notificationJson['data'], type), NotificationType.personalizedDietIsDefined =>
NotificationType.chosenPlanFinishedToClient => ChosenPlanFinishedToClientNotification.fromJson(notificationJson['data'], type), PersonalizedDietIsDefinedNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.planSubscriptionCanceledToCustomer => PlanSubscriptionCanceledToAuthorNotification.fromJson(notificationJson['data'], type), NotificationType.chosenPlanFinishedToClient =>
NotificationType.chosenPlanStartedToConsultantNotification => ChosenPlanStartedToConsultantNotification.fromJson(notificationJson['data'], type), ChosenPlanFinishedToClientNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.planSubscriptionCanceledToCustomer =>
PlanSubscriptionCanceledToAuthorNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.chosenPlanStartedToConsultantNotification =>
ChosenPlanStartedToConsultantNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.chosenPlanTomorrowReminderToConsultantNotification => NotificationType.chosenPlanTomorrowReminderToConsultantNotification =>
ChosenPlanTomorrowReminderToConsultantNotification.fromJson(notificationJson['data'], type), ChosenPlanTomorrowReminderToConsultantNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.planSubscriptionPaidToAuthor => PlanSubscriptionPaidToAuthorNotification.fromJson(notificationJson['data'], type), NotificationType.planSubscriptionPaidToAuthor =>
NotificationType.chosenPlanFinishedToConsultant => ChosenPlanFinishedToConsultantNotification.fromJson(notificationJson['data'], type), PlanSubscriptionPaidToAuthorNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.chosenPlanFinishedToConsultant =>
ChosenPlanFinishedToConsultantNotification.fromJson(notificationJson['data'], type, isRead: readDate != null),
NotificationType.unknown => UnknownNotification(type: type), NotificationType.unknown => UnknownNotification(type: type),
}; };
} catch (e) { } catch (e) {
@@ -43,4 +53,12 @@ class NotificationsService {
rethrow; rethrow;
} }
} }
Future<void> markNotificationsAsRead() async {
try {
await dio.post('/api/profile/mark_notifications_as_readed');
} catch (e) {
rethrow;
}
}
} }

View File

@@ -424,6 +424,9 @@ class MessageLookup extends MessageLookupByLibrary {
"Почта успешно скопирована", "Почта успешно скопирована",
), ),
"male": MessageLookupByLibrary.simpleMessage("Мужской"), "male": MessageLookupByLibrary.simpleMessage("Мужской"),
"markAsRead": MessageLookupByLibrary.simpleMessage(
"Отметить всё прочитанным",
),
"meal": MessageLookupByLibrary.simpleMessage("Приём пищи"), "meal": MessageLookupByLibrary.simpleMessage("Приём пищи"),
"mealComment": MessageLookupByLibrary.simpleMessage( "mealComment": MessageLookupByLibrary.simpleMessage(
"Комментарий к приему пищи", "Комментарий к приему пищи",

View File

@@ -3334,6 +3334,16 @@ class S {
args: [name, planName], args: [name, planName],
); );
} }
/// `Отметить всё прочитанным`
String get markAsRead {
return Intl.message(
'Отметить всё прочитанным',
name: 'markAsRead',
desc: '',
args: [],
);
}
} }
class AppLocalizationDelegate extends LocalizationsDelegate<S> { class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View File

@@ -396,6 +396,7 @@
"tomorrowYourPlanWillStart": "Завтра начнется прохождение плана «{planName}»", "tomorrowYourPlanWillStart": "Завтра начнется прохождение плана «{planName}»",
"planStarted": "План «{planName}» начался", "planStarted": "План «{planName}» начался",
"userCanceldThePlanSubscription": "Пользователь {name} отменил подписку на план «{planName}»", "userCanceldThePlanSubscription": "Пользователь {name} отменил подписку на план «{planName}»",
"userSubscribedToPlan": "Пользователь {name} подписался на план «{planName}»" "userSubscribedToPlan": "Пользователь {name} подписался на план «{planName}»",
"markAsRead": "Отметить всё прочитанным"
} }