forked from eatvio/eatvio_app
243 lines
12 KiB
Dart
243 lines
12 KiB
Dart
import 'package:cached_network_image/cached_network_image.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/widgets/custom_outlined_button.dart';
|
|
import 'package:eatvio_app/features/recipe/models/my_recipe_model.dart';
|
|
import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/my_recieps_cubit.dart';
|
|
import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/my_recipes_state.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_html/flutter_html.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:share_plus/share_plus.dart';
|
|
|
|
class MyRecipeWidget extends StatelessWidget {
|
|
final MyRecipeModel recipe;
|
|
|
|
const MyRecipeWidget({
|
|
super.key,
|
|
required this.recipe,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// final s = S.of(context);
|
|
return DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
color: Colors.white,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Stack(
|
|
children: [
|
|
InkWell(
|
|
// onTap: () => GoRouter.of(context).pushNamed('aboutDietScreen', extra: {'diet': widget.diet, 'navigateToComments': false}),
|
|
child: ClipRRect(
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
|
|
child: CachedNetworkImage(
|
|
imageUrl: '$baseUrl/storage/${recipe.image}',
|
|
fit: BoxFit.fitWidth,
|
|
width: MediaQuery.of(context).size.width,
|
|
),
|
|
),
|
|
),
|
|
// Positioned(
|
|
// bottom: 16,
|
|
// child: SizedBox(
|
|
// width: MediaQuery.sizeOf(context).width,
|
|
// child: InfoRow(diet: widget.diet, itemsBackgroundColor: appTheme.whiteA700, disableDescriptionOfTypes: true, type: ProductType.diet),
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text(
|
|
recipe.title!,
|
|
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
|
|
),
|
|
),
|
|
if (recipe.description.isNotEmpty) ...[
|
|
const SizedBox(
|
|
height: 12,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Html(
|
|
data: recipe.description.length > 200 ? '${recipe.description.substring(0, 200)}...' : recipe.description,
|
|
style: {
|
|
"*": Style(
|
|
margin: Margins.zero,
|
|
color: appTheme.black,
|
|
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
|
|
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
|
|
),
|
|
},
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
const SizedBox(height: 20),
|
|
BlocBuilder<MyRecipesCubit, MyRecipesState>(
|
|
builder: (BuildContext context, MyRecipesState state) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: CustomOutlinedButton(
|
|
onPressed: () async {
|
|
// if (state.selectedStateIndex == 1) {
|
|
// final result = await context.read<MyDietsCubit>().publishDiet(widget.diet.id);
|
|
// if (result) {
|
|
// if (!context.mounted) return;
|
|
// showBottomSheetWithBlur(
|
|
// context: context,
|
|
// child: SuccessPublishedDietOrPlanBottomSheet(title: widget.diet.name),
|
|
// );
|
|
// await context.read<MyDietsCubit>().loadAllDiets();
|
|
// } else {
|
|
// showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
|
// }
|
|
// } else if (state.selectedStateIndex == 2) {
|
|
// } else {
|
|
// GoRouter.of(context).pushNamed(CreateDietScreen.name, extra: widget.diet);
|
|
// }
|
|
},
|
|
text: '',
|
|
// text: switch (state.selectedStateIndex) {
|
|
// 1 => s.publish,
|
|
// 2 => s.toOffer,
|
|
// _ => s.edit,
|
|
// },
|
|
height: 52,
|
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
|
buttonStyle: ButtonStyle(
|
|
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
|
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
),
|
|
),
|
|
),
|
|
// if (state.selectedStateIndex == 0) ...[
|
|
const SizedBox(width: 6),
|
|
CustomOutlinedButton(
|
|
onPressed: () async {
|
|
final box = context.findRenderObject() as RenderBox?;
|
|
await SharePlus.instance.share(
|
|
ShareParams(
|
|
uri: Uri.parse('$baseUrl/ru/recipe/${recipe.id}'),
|
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
|
),
|
|
);
|
|
},
|
|
height: 52,
|
|
width: 52,
|
|
leftIcon: SvgPicture.asset(
|
|
'assets/icons/share2.svg',
|
|
width: 20,
|
|
height: 20,
|
|
colorFilter: ColorFilter.mode(appTheme.whiteA700, BlendMode.srcIn),
|
|
),
|
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.red),
|
|
buttonStyle: ButtonStyle(
|
|
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
|
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
),
|
|
text: '',
|
|
),
|
|
],
|
|
// ],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: CustomOutlinedButton(
|
|
onPressed: () async {
|
|
// if (state.selectedStateIndex == 0) {
|
|
// final result = await context.read<MyDietsCubit>().unpublishDiet(widget.diet.id);
|
|
// if (result) {
|
|
// if (!context.mounted) return;
|
|
// showBottomSheetWithBlur(
|
|
// context: context,
|
|
// height: 250,
|
|
// child: DietDraftedBottomSheet(title: widget.diet.name),
|
|
// );
|
|
// await context.read<MyDietsCubit>().loadAllDiets();
|
|
// } else {
|
|
// showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
|
// }
|
|
// } else {
|
|
// await showErrorDialog(context, title: 'Предупреждение', description: 'Вы можете создать новую диету на основе существующей.');
|
|
// AppRouter.navigatorKey.currentContext?.pushNamed(CreateDietScreen.name, extra: widget.diet);
|
|
// }
|
|
},
|
|
text: '',
|
|
// text: switch (state.selectedStateIndex) {
|
|
// 0 => s.removeFromActive,
|
|
// _ => s.edit,
|
|
// },
|
|
height: 52,
|
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.black),
|
|
buttonStyle: ButtonStyle(
|
|
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
|
backgroundColor: WidgetStatePropertyAll(appTheme.lightGray0),
|
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 6),
|
|
CustomOutlinedButton(
|
|
onPressed: () async {
|
|
// final result = await context.read<MyDietsCubit>().deleteDiet(widget.diet.id);
|
|
// if (result) {
|
|
// if (!context.mounted) return;
|
|
// showBottomSheetWithBlur(
|
|
// context: context,
|
|
// child: DietDeletedBottomSheet(title: widget.diet.name),
|
|
// );
|
|
// await context.read<MyDietsCubit>().loadAllDiets();
|
|
// }
|
|
},
|
|
height: 52,
|
|
width: 52,
|
|
leftIcon: SvgPicture.asset(
|
|
'assets/icons/trash_can.svg',
|
|
width: 20,
|
|
height: 20,
|
|
),
|
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.red),
|
|
buttonStyle: ButtonStyle(
|
|
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
|
backgroundColor: WidgetStatePropertyAll(appTheme.lightGray0),
|
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
),
|
|
text: '',
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|