forked from eatvio/eatvio_app
feat: Add user recipe management and creation functionality, including models, widgets, cubits, repositories, and tests.
This commit is contained in:
@@ -12,7 +12,6 @@ import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/m
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/presentation/bloc/create_recipe_cubit/create_recipe_cubit.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/presentation/pages/recipe_create_screen.dart';
|
||||
import 'package:eatvio_app/core/widgets/markdown_html_widget.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
@@ -144,80 +143,112 @@ class _MyRecipeWidgetState extends State<MyRecipeWidget> {
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: PopupMenuButton<int>(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
offset: const Offset(0, 50),
|
||||
itemBuilder: (context) => [
|
||||
if (!isDraft)
|
||||
PopupMenuItem(
|
||||
onTap: () async {
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
uri: Uri.parse('${sl<AppConfig>().baseUrl}/ru/recipe/${widget.recipe.slug}'),
|
||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||
child: isDraft
|
||||
? CustomOutlinedButton(
|
||||
onPressed: () {
|
||||
context.push(RecipeCreateScreen.path, extra: widget.recipe.toRecipe());
|
||||
},
|
||||
height: 52,
|
||||
buttonStyle: ButtonStyle(
|
||||
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.lightGray0),
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
),
|
||||
text: 'Редактировать',
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.black),
|
||||
)
|
||||
: PopupMenuButton<int>(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
offset: const Offset(0, 50),
|
||||
itemBuilder: (context) => [
|
||||
if (!isDraft)
|
||||
PopupMenuItem(
|
||||
onTap: () async {
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
uri: Uri.parse('\${sl<AppConfig>().baseUrl}/ru/recipe/\${widget.recipe.slug}'),
|
||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.share, size: 20, color: appTheme.black),
|
||||
const SizedBox(width: 8),
|
||||
Text(S.of(context).share, style: TextStyles.textSMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.share, size: 20, color: appTheme.black),
|
||||
const SizedBox(width: 8),
|
||||
Text(S.of(context).share, style: TextStyles.textSMedium),
|
||||
],
|
||||
if (!isDraft)
|
||||
PopupMenuItem(
|
||||
onTap: () async {
|
||||
final result = await context.read<MyRecipesCubit>().draftRecipe(widget.recipe.id);
|
||||
if (result) {
|
||||
showSuccessToast('Рецепт перенесен в черновики');
|
||||
if (context.mounted) {
|
||||
context.read<MyRecipesCubit>().getMyRecipes();
|
||||
}
|
||||
} else {
|
||||
showErrorToast('Не удалось перенести в черновики');
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.archive_outlined, size: 20, color: appTheme.black),
|
||||
const SizedBox(width: 8),
|
||||
const Text('В черновик', style: TextStyles.textSMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () {},
|
||||
height: 52,
|
||||
width: 52,
|
||||
buttonStyle: ButtonStyle(
|
||||
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
),
|
||||
text: s.share,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
),
|
||||
),
|
||||
if (widget.recipe.state == 'active' || isDraft)
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
context.push(RecipeCreateScreen.path, extra: widget.recipe);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.edit, size: 20, color: appTheme.black),
|
||||
const SizedBox(width: 8),
|
||||
Text(S.of(context).edit, style: TextStyles.textSMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () {},
|
||||
height: 52,
|
||||
width: 52,
|
||||
buttonStyle: ButtonStyle(
|
||||
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
),
|
||||
text: isDraft ? '...' : s.share,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (isDraft)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
// Publish draft
|
||||
context.read<CreateRecipeCubit>().publishRecipe(true, widget.recipe.slug).then((success) {
|
||||
if (success && context.mounted) {
|
||||
context.read<MyRecipesCubit>().setDraftedState();
|
||||
}
|
||||
});
|
||||
final recipeModel = widget.recipe.toRecipeModel();
|
||||
final success = await context.read<MyRecipesCubit>().publishDraft(recipeModel, widget.recipe.slug);
|
||||
if (success && context.mounted) {
|
||||
showSuccessToast('Черновик опубликован');
|
||||
context.read<MyRecipesCubit>().setDraftedState();
|
||||
} else {
|
||||
showErrorToast('Заполните все необходимые поля для публикации рецепта');
|
||||
if (context.mounted) {
|
||||
context.push(RecipeCreateScreen.path, extra: {
|
||||
'recipe': widget.recipe.toRecipe(),
|
||||
'autoValidate': true,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: appTheme.blueA400,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
height: 52,
|
||||
buttonStyle: ButtonStyle(
|
||||
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
),
|
||||
child: Text('Опубликовать', style: TextStyles.textSMedium.copyWith(color: Colors.white)),
|
||||
text: 'Опубликовать',
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user