Files
eatvio_app/lib/features/notifications/presentation/widgets/notification_widget.dart
2025-05-22 22:00:01 +07:00

258 lines
9.6 KiB
Dart

import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/features/my_finance/presentation/pages/card_settings.dart';
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class NotificationWidget extends StatelessWidget {
const NotificationWidget({super.key, required this.notification});
final BaseNotificationModel notification;
@override
Widget build(BuildContext context) {
return switch (notification) {
PlanSubscriptionStartedToAuthorNotification() => _PlanSubscriptionStartedToAuthorWidget(
notification: notification as PlanSubscriptionStartedToAuthorNotification,
),
PlanSubscriptionCanceledToAuthorNotification() => _PlanSubscriptionCanceledToAuthorWidget(
notification: notification as PlanSubscriptionCanceledToAuthorNotification,
),
ChosenPlanStartedToClientNotification() => _ChosenPlanStartedToClientWidget(
notification: notification as ChosenPlanStartedToClientNotification,
),
ChosenPlanTomorrowReminderToClientNotification() => _ChosenPlanTomorrowReminderToClientWidget(
notification: notification as ChosenPlanTomorrowReminderToClientNotification,
),
DiaryReminderNotification() => _DiaryReminderWidget(
notification: notification as DiaryReminderNotification,
),
ConsultantLeftCommentNotification() => _ConsultantLeftCommentWidget(
notification: notification as ConsultantLeftCommentNotification,
),
PersonalizedDietIsDefinedNotification() => _PersonalizedDietIsDefinedWidget(
notification: notification as PersonalizedDietIsDefinedNotification,
),
ChosenPlanFinishedToClientNotification() => _ChosenPlanFinishedToClientWidget(
notification: notification as ChosenPlanFinishedToClientNotification,
),
PlanSubscriptionCanceledToCustomerNotification() => _PlanSubscriptionCanceledToCustomerWidget(
notification: notification as PlanSubscriptionCanceledToCustomerNotification,
),
ChosenPlanStartedToConsultantNotification() => _ChosenPlanStartedToConsultantWidget(
notification: notification as ChosenPlanStartedToConsultantNotification,
),
ChosenPlanTomorrowReminderToConsultantNotification() => _ChosenPlanTomorrowReminderToConsultantWidget(
notification: notification as ChosenPlanTomorrowReminderToConsultantNotification,
),
PlanSubscriptionPaidToAuthorNotification() => throw _PlanSubscriptionPaidToAuthorWidget(
notification: notification as PlanSubscriptionPaidToAuthorNotification,
),
ChosenPlanFinishedToConsultantNotification() => _ChosenPlanFinishedToConsultantWidget(
notification: notification as ChosenPlanFinishedToConsultantNotification,
),
UnknownNotification() => const SizedBox.shrink(),
};
}
}
class _PlanSubscriptionStartedToAuthorWidget extends StatelessWidget {
const _PlanSubscriptionStartedToAuthorWidget({required this.notification});
final PlanSubscriptionStartedToAuthorNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.userSubscribedToPlan(notification.customerName, notification.planName),
);
}
}
class _PlanSubscriptionCanceledToAuthorWidget extends StatelessWidget {
const _PlanSubscriptionCanceledToAuthorWidget({required this.notification});
final PlanSubscriptionCanceledToAuthorNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.userCanceldThePlanSubscription(notification.customerName, notification.planName),
);
}
}
class _ChosenPlanStartedToClientWidget extends StatelessWidget {
const _ChosenPlanStartedToClientWidget({required this.notification});
final ChosenPlanStartedToClientNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.planStarted(notification.planName),
);
}
}
class _ChosenPlanTomorrowReminderToClientWidget extends StatelessWidget {
const _ChosenPlanTomorrowReminderToClientWidget({required this.notification});
final ChosenPlanTomorrowReminderToClientNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.tomorrowYourPlanWillStart(notification.planName),
);
}
}
class _DiaryReminderWidget extends StatelessWidget {
const _DiaryReminderWidget({required this.notification});
final DiaryReminderNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.fillYasterday,
);
}
}
class _ConsultantLeftCommentWidget extends StatelessWidget {
const _ConsultantLeftCommentWidget({required this.notification});
final ConsultantLeftCommentNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.consultantLeftComment(notification.date),
);
}
}
class _PersonalizedDietIsDefinedWidget extends StatelessWidget {
const _PersonalizedDietIsDefinedWidget({required this.notification});
final PersonalizedDietIsDefinedNotification notification;
@override
Widget build(BuildContext context) {
return Container();
}
}
class _ChosenPlanFinishedToClientWidget extends StatelessWidget {
const _ChosenPlanFinishedToClientWidget({required this.notification});
final ChosenPlanFinishedToClientNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: '${s.congratsYouHaveFinishedPlan} «${notification.planName}»',
);
}
}
class _PlanSubscriptionCanceledToCustomerWidget extends StatelessWidget {
const _PlanSubscriptionCanceledToCustomerWidget({required this.notification});
final PlanSubscriptionCanceledToCustomerNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.youCanceledSubscriptionToPlan(notification.planName),
);
}
}
class _ChosenPlanStartedToConsultantWidget extends StatelessWidget {
const _ChosenPlanStartedToConsultantWidget({required this.notification});
final ChosenPlanStartedToConsultantNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.planWithUserStarted(notification.planName, notification.customerName),
);
}
}
class _ChosenPlanTomorrowReminderToConsultantWidget extends StatelessWidget {
const _ChosenPlanTomorrowReminderToConsultantWidget({required this.notification});
final ChosenPlanTomorrowReminderToConsultantNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.tommorowPlanWithUserWillStart(notification.planName, notification.customerName),
);
}
}
class _PlanSubscriptionPaidToAuthorWidget extends StatelessWidget {
const _PlanSubscriptionPaidToAuthorWidget({required this.notification});
final PlanSubscriptionPaidToAuthorNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return _BaseNotificationWidget(
notificationsText: s.userPaidThePlan(notification.customerName, notification.planName),
);
}
}
class _ChosenPlanFinishedToConsultantWidget extends StatelessWidget {
const _ChosenPlanFinishedToConsultantWidget({required this.notification});
final ChosenPlanFinishedToConsultantNotification notification;
@override
Widget build(BuildContext context) {
final s = S.of(context);
return Container(
child: Column(children: [
Text(
'${s.congratsYouHaveFinishedPlan} «${notification.planName}»',
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
Text(
s.userConfirmedPlanCompletionWithoutSum,
style: TextStyles.textSMedium.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
CustomOutlinedButton(
text: s.collectCharge,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.green)),
onPressed: () {
GoRouter.of(context).pushNamed(CardSettingsScreen.name, extra: notification.planId);
},
),
const SizedBox(height: 12),
]),
);
}
}
// CardSettingsScreen
class _BaseNotificationWidget extends StatelessWidget {
const _BaseNotificationWidget({required this.notificationsText});
final String notificationsText;
@override
Widget build(BuildContext context) {
return SizedBox(
width: MediaQuery.sizeOf(context).width * 0.6,
child: Text(
notificationsText,
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
),
);
}
}