Files
eatvio_app/lib/features/chat/presentation/widgets/order_card.dart
2025-04-04 20:21:31 +07:00

139 lines
5.1 KiB
Dart

import 'package:eatvio_app/core/const.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/utils/localization_utils.dart';
import 'package:eatvio_app/core/utils/string_extentions.dart';
import 'package:eatvio_app/core/widgets/item_widget.dart';
import 'package:eatvio_app/core/widgets/loader.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
class OrderCard extends StatefulWidget {
final PlanModel plan;
final String optionType;
final bool isCustomerView;
final Future<void> Function() onCancel;
const OrderCard({super.key, required this.plan, required this.isCustomerView, required this.optionType, required this.onCancel});
@override
State<OrderCard> createState() => _OrderCardState();
}
class _OrderCardState extends State<OrderCard> {
bool isLoading = false;
@override
Widget build(BuildContext context) {
final optionIndex = int.parse(widget.optionType.characters.last);
final option = switch (optionIndex) {
1 => widget.plan.packet1Options,
2 => widget.plan.packet2Options,
3 => widget.plan.packet3Options,
_ => null,
};
final s = S.of(context);
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.only(top: 8, bottom: 12, left: 8, right: 8),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), color: appTheme.gray60004),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 200,
width: double.infinity,
child: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.network(
'$baseUrl/storage/${widget.plan.image}',
width: double.infinity,
fit: BoxFit.cover,
),
),
Positioned(
left: 0,
bottom: 44,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
child: Text(
'${widget.plan.duration} ${getDayForm(widget.plan.duration, s).capitalize()}',
style: TextStyles.textSMedium.copyWith(color: appTheme.whiteA700),
),
),
),
Positioned(
left: 0,
bottom: 12,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: appTheme.greenA700,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(12),
bottomRight: Radius.circular(12),
),
),
child: Text(
'${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}₽',
style: TextStyles.textSMedium.copyWith(color: appTheme.whiteA700),
),
),
),
],
),
),
const SizedBox(height: 12),
Text(
widget.plan.name,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 12),
Text(
'${s.option}: ${option?.short ?? ''}',
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
const SizedBox(height: 8),
if (option != null)
...option.items
.map(
(element) => Padding(
padding: const EdgeInsets.only(bottom: 4),
child: ItemWidget(
reversed: true,
iconSize: 12,
text: element,
),
),
)
,
if (widget.isCustomerView) ...[
const SizedBox(height: 8),
isLoading
? const Loader()
: GestureDetector(
onTap: () async {
setState(() => isLoading = true);
await widget.onCancel();
setState(() => isLoading = false);
},
child: Text(
s.cancel_order,
style: TextStyles.textSMedium.copyWith(color: appTheme.strongRed),
),
),
],
],
),
);
}
}