fix(diary): added proccesing of future dates and fixed deleted portions

This commit is contained in:
Username1548
2025-04-08 21:28:40 +07:00
parent 245c854754
commit 823dc78490
25 changed files with 1038 additions and 371 deletions

View File

@@ -0,0 +1,32 @@
import 'dart:developer';
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
import 'package:eatvio_app/features/order_info/cubit/order_info_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class OrderInfoCubit extends Cubit<OrderInfoState> {
OrderInfoCubit({required this.chatRepository}) : super(OrderInfoState());
final ChatRepository chatRepository;
Future<String?> getPaymentLink() async {
try {
final plan = state.chosenPlan;
if (plan == null) return null;
final paymentModel = await chatRepository.getPaymentLink(id: plan.id);
return paymentModel.paymentUrl;
} catch (e) {
log(e.toString());
return null;
}
}
Future<void> getChosenPlan(int id) async{
try {
emit(state.copyWith(isLoading: true));
emit(state.copyWith(isLoading: false));
} catch (e) {
log(e.toString());
emit(state.copyWith(isLoading: false));
}
}
}

View File

@@ -0,0 +1,14 @@
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'order_info_state.freezed.dart';
@freezed
class OrderInfoState with _$OrderInfoState {
factory OrderInfoState({
@Default(false) bool isLoading,
@Default(null) ChosenPlanModel? chosenPlan,
}) = _OrderInfoState;
}

View File

@@ -0,0 +1,185 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'order_info_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$OrderInfoState {
bool get isLoading => throw _privateConstructorUsedError;
ChosenPlanModel? get chosenPlan => throw _privateConstructorUsedError;
/// Create a copy of OrderInfoState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OrderInfoStateCopyWith<OrderInfoState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OrderInfoStateCopyWith<$Res> {
factory $OrderInfoStateCopyWith(
OrderInfoState value, $Res Function(OrderInfoState) then) =
_$OrderInfoStateCopyWithImpl<$Res, OrderInfoState>;
@useResult
$Res call({bool isLoading, ChosenPlanModel? chosenPlan});
$ChosenPlanModelCopyWith<$Res>? get chosenPlan;
}
/// @nodoc
class _$OrderInfoStateCopyWithImpl<$Res, $Val extends OrderInfoState>
implements $OrderInfoStateCopyWith<$Res> {
_$OrderInfoStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OrderInfoState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? chosenPlan = freezed,
}) {
return _then(_value.copyWith(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
chosenPlan: freezed == chosenPlan
? _value.chosenPlan
: chosenPlan // ignore: cast_nullable_to_non_nullable
as ChosenPlanModel?,
) as $Val);
}
/// Create a copy of OrderInfoState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ChosenPlanModelCopyWith<$Res>? get chosenPlan {
if (_value.chosenPlan == null) {
return null;
}
return $ChosenPlanModelCopyWith<$Res>(_value.chosenPlan!, (value) {
return _then(_value.copyWith(chosenPlan: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$OrderInfoStateImplCopyWith<$Res>
implements $OrderInfoStateCopyWith<$Res> {
factory _$$OrderInfoStateImplCopyWith(_$OrderInfoStateImpl value,
$Res Function(_$OrderInfoStateImpl) then) =
__$$OrderInfoStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool isLoading, ChosenPlanModel? chosenPlan});
@override
$ChosenPlanModelCopyWith<$Res>? get chosenPlan;
}
/// @nodoc
class __$$OrderInfoStateImplCopyWithImpl<$Res>
extends _$OrderInfoStateCopyWithImpl<$Res, _$OrderInfoStateImpl>
implements _$$OrderInfoStateImplCopyWith<$Res> {
__$$OrderInfoStateImplCopyWithImpl(
_$OrderInfoStateImpl _value, $Res Function(_$OrderInfoStateImpl) _then)
: super(_value, _then);
/// Create a copy of OrderInfoState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? chosenPlan = freezed,
}) {
return _then(_$OrderInfoStateImpl(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
chosenPlan: freezed == chosenPlan
? _value.chosenPlan
: chosenPlan // ignore: cast_nullable_to_non_nullable
as ChosenPlanModel?,
));
}
}
/// @nodoc
class _$OrderInfoStateImpl implements _OrderInfoState {
_$OrderInfoStateImpl({this.isLoading = false, this.chosenPlan = null});
@override
@JsonKey()
final bool isLoading;
@override
@JsonKey()
final ChosenPlanModel? chosenPlan;
@override
String toString() {
return 'OrderInfoState(isLoading: $isLoading, chosenPlan: $chosenPlan)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OrderInfoStateImpl &&
(identical(other.isLoading, isLoading) ||
other.isLoading == isLoading) &&
(identical(other.chosenPlan, chosenPlan) ||
other.chosenPlan == chosenPlan));
}
@override
int get hashCode => Object.hash(runtimeType, isLoading, chosenPlan);
/// Create a copy of OrderInfoState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$OrderInfoStateImplCopyWith<_$OrderInfoStateImpl> get copyWith =>
__$$OrderInfoStateImplCopyWithImpl<_$OrderInfoStateImpl>(
this, _$identity);
}
abstract class _OrderInfoState implements OrderInfoState {
factory _OrderInfoState(
{final bool isLoading,
final ChosenPlanModel? chosenPlan}) = _$OrderInfoStateImpl;
@override
bool get isLoading;
@override
ChosenPlanModel? get chosenPlan;
/// Create a copy of OrderInfoState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$OrderInfoStateImplCopyWith<_$OrderInfoStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -1,80 +1,172 @@
import 'package:eatvio_app/core/locator_service.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/loader.dart';
import 'package:eatvio_app/features/diets/presentation/widgets/author_card.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/features/order_info/cubit/order_info_cubit.dart';
import 'package:eatvio_app/features/order_info/cubit/order_info_state.dart';
import 'package:eatvio_app/features/order_info/presentation/widgets/payment_banner.dart';
import 'package:eatvio_app/features/order_info/presentation/widgets/plan_info.dart';
import 'package:eatvio_app/features/order_info/presentation/widgets/plan_props.dart';
import 'package:eatvio_app/features/order_info/presentation/widgets/plan_state.dart';
import 'package:eatvio_app/features/order_info/presentation/widgets/plan_status_box.dart';
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:eatvio_app/core/widgets/option_widget.dart';
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class InfoByOrderScreen extends StatefulWidget {
class InfoByOrderScreen extends StatelessWidget {
static const name = 'infoByOrderScreen';
static const path = '/info-by-order-screen';
final ChosenPlanModel plan;
const InfoByOrderScreen({
super.key,
required this.plan,
});
const InfoByOrderScreen({super.key, this.successfulPayment, required this.planId});
final bool? successfulPayment;
final int planId;
@override
State<InfoByOrderScreen> createState() => _InfoByOrderScreenState();
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => sl<OrderInfoCubit>()..getChosenPlan(planId),
child: InfoByOrderScreenContent(
successfulPayment: successfulPayment,
planId: planId,
),
);
}
}
class _InfoByOrderScreenState extends State<InfoByOrderScreen> {
class InfoByOrderScreenContent extends StatefulWidget {
static const name = 'infoByOrderScreen';
static const path = '/info-by-order-screen';
const InfoByOrderScreenContent({
super.key,
required this.planId,
required this.successfulPayment,
});
final int planId;
final bool? successfulPayment;
@override
State<InfoByOrderScreenContent> createState() => _InfoByOrderScreenContentState();
}
class _InfoByOrderScreenContentState extends State<InfoByOrderScreenContent> {
@override
Widget build(BuildContext context) {
final s = S.of(context);
PacketOptions? chosenOption;
if (widget.plan.optionType == 'options1') {
chosenOption = widget.plan.plan.packet1Options;
} else if (widget.plan.optionType == 'options2') {
chosenOption = widget.plan.plan.packet2Options;
} else {
chosenOption = widget.plan.plan.packet3Options;
}
return Scaffold(
backgroundColor: appTheme.gray100,
appBar: AppBar(
title: Text(
s.infoAboutOrder,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
leading: IconButton(icon: const Icon(Icons.arrow_back), onPressed: () {}),
),
body: SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 8),
AuthorCard(
author: widget.plan.plan.author,
title: s.plan_seller,
titleStyle: TextStyles.textSSemibold.copyWith(color: appTheme.gray),
backgroundColor: appTheme.whiteA700,
return BlocBuilder<OrderInfoCubit, OrderInfoState>(
builder: (context, state) {
final plan = state.chosenPlan;
if (state.isLoading) {
Scaffold(
appBar: AppBar(
title: Text(
s.infoAboutOrder,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 8),
PlanProps(planDuration: widget.plan.plan.duration, planPrice: chosenOption?.price.toDouble() ?? 0, planStatus: PlanStatusValues.paymentFailed),
const SizedBox(height: 8),
PlanInfo(
title: widget.plan.plan.name,
description: widget.plan.plan.details,
imagePath: widget.plan.plan.image,
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
GoRouter.of(context).pop();
}),
),
body: const Center(
child: Loader(),
),
);
}
if (plan == null) {
return Scaffold(
appBar: AppBar(
title: Text(
s.infoAboutOrder,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 8),
OptionWidget(
option: chosenOption,
disableDuration: true,
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
GoRouter.of(context).pop();
}),
),
body: Center(
child: Text(
s.sorry_we_did_not_find_the_plan,
style: TextStyles.textSSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 8),
PlanState(
state: widget.plan.chosenPlanState,
),
);
}
PacketOptions? chosenOption;
if (plan.optionType == 'options1') {
chosenOption = plan.plan.packet1Options;
} else if (plan.optionType == 'options2') {
chosenOption = plan.plan.packet2Options;
} else {
chosenOption = plan.plan.packet3Options;
}
PlanStatusValues planStatus;
if (widget.successfulPayment == true) {
planStatus = PlanStatusValues.paid;
} else if (widget.successfulPayment == false) {
planStatus = PlanStatusValues.paymentFailed;
} else if (plan.chosenPlanState == ChosenPlanStateEnum.statePaid) {
planStatus = PlanStatusValues.paid;
} else {
planStatus = PlanStatusValues.pendingPayment;
}
return Scaffold(
backgroundColor: appTheme.gray100,
appBar: AppBar(
title: Text(
s.infoAboutOrder,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 30),
],
),
));
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
GoRouter.of(context).pop();
}),
),
body: SingleChildScrollView(
child: Column(
children: [
if (widget.successfulPayment != null) ...[
const SizedBox(height: 8),
PaymentBanner(
successfulPayment: widget.successfulPayment ?? false,
),
],
const SizedBox(height: 8),
AuthorCard(
author: plan.plan.author,
title: s.plan_seller,
titleStyle: TextStyles.textSSemibold.copyWith(color: appTheme.gray),
backgroundColor: appTheme.whiteA700,
),
const SizedBox(height: 8),
PlanProps(planDuration: plan.plan.duration, planPrice: chosenOption?.price.toDouble() ?? 0, planStatus: planStatus),
const SizedBox(height: 8),
PlanInfo(
title: plan.plan.name,
description: plan.plan.details,
imagePath: plan.plan.image,
),
const SizedBox(height: 8),
OptionWidget(
option: chosenOption,
disableDuration: true,
),
const SizedBox(height: 8),
PlanState(
state: plan.chosenPlanState,
),
const SizedBox(height: 30),
],
),
));
},
);
}
}

View File

@@ -0,0 +1,161 @@
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/core/widgets/loader.dart';
import 'package:eatvio_app/core/widgets/main_background_bouble.dart';
import 'package:eatvio_app/features/chat/presentation/pages/payment_screen.dart';
import 'package:eatvio_app/features/order_info/cubit/order_info_cubit.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class PaymentBanner extends StatefulWidget {
const PaymentBanner({
super.key,
required this.successfulPayment,
});
final bool successfulPayment;
@override
State<PaymentBanner> createState() => _PaymentBannerState();
}
class _PaymentBannerState extends State<PaymentBanner> {
bool isLoading = false;
@override
Widget build(BuildContext context) {
final s = S.of(context);
final size = MediaQuery.sizeOf(context);
return MainBackgroundBouble(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Stack(children: [
Positioned(
left: 0,
top: 0,
bottom: 0,
child: Container(
width: 4,
decoration: BoxDecoration(
color: widget.successfulPayment ? appTheme.blueA400 : appTheme.strongRed,
borderRadius: const BorderRadius.only(topRight: Radius.circular(20), bottomRight: Radius.circular(20))),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: widget.successfulPayment
? [
SizedBox(
width: size.width * 0.6,
child: Text(
s.cunsutation_was_paid_successfully,
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
),
const SizedBox(
height: 8,
),
SizedBox(
width: size.width * 0.6,
child: Text(
s.wait_for_start_day,
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
),
),
const SizedBox(
height: 16,
),
isLoading
? const Center(child: Loader())
: CustomOutlinedButton(
text: s.go_to_diary,
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle:
ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
onPressed: () async {
GoRouter.of(context).pushReplacement('/diary-screen');
},
),
isLoading
? const Center(child: Loader())
: CustomOutlinedButton(
text: s.back_to_chat,
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle:
ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
onPressed: () {
GoRouter.of(context).pop();
},
)
]
: [
SizedBox(
width: size.width * 0.6,
child: Text(
s.smth_went_wrong_payment_failed,
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
),
),
const SizedBox(
height: 8,
),
SizedBox(
width: size.width * 0.6,
child: Text(
s.try_again_2,
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
),
),
const SizedBox(
height: 16,
),
isLoading
? const Center(child: Loader())
: CustomOutlinedButton(
text: s.pay,
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle:
ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)),
onPressed: () async {
final planId = context.read<OrderInfoCubit>().state.chosenPlan?.id;
setState(() {
isLoading = true;
});
final paymentLink = await context.read<OrderInfoCubit>().getPaymentLink();
setState(() {
isLoading = false;
});
if (paymentLink != null && planId != null) {
if (!context.mounted) return;
GoRouter.of(context).pushReplacement(
PaymentScreen.path,
extra: {'url': paymentLink, 'planId': planId},
);
}
},
)
],
),
)
])
// ? Column(children: [
// SizedBox(
// width: size.width * 0.6,
// child: Text(
// s.smth_went_wrong_payment_failed,
// style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
// ),
// ),
// ])
// : Padding(
// padding: const EdgeInsets.only(right: 16),
// child: ,
// ),
);
}
}