forked from eatvio/eatvio_app
feat(my_diets): merge conflict fixes
This commit is contained in:
@@ -36,8 +36,11 @@ class MyDietWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyDietWidgetState extends State<MyDietWidget> {
|
||||
void _editDiet(Diet diet) {
|
||||
GoRouter.of(context).pushNamed(CreateDietScreen.name, extra: {'diet': diet, 'isEditing': true});
|
||||
|
||||
Future<void> _editDiet(Diet diet, BuildContext context) async{
|
||||
await GoRouter.of(context).pushNamed(CreateDietScreen.name, extra: {'diet': diet, 'isEditing': true});
|
||||
if (!context.mounted) return;
|
||||
await context.read<MyDietsCubit>().loadAllDiets();
|
||||
}
|
||||
|
||||
void _suggestDiet(Diet diet) {
|
||||
@@ -49,16 +52,19 @@ class _MyDietWidgetState extends State<MyDietWidget> {
|
||||
}
|
||||
|
||||
Future<void> _publishDiet(Diet diet, BuildContext context) async {
|
||||
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('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
final statusCode = await context.read<MyDietsCubit>().publishDiet(widget.diet.id);
|
||||
switch (statusCode) {
|
||||
case 201:
|
||||
if (!context.mounted) return;
|
||||
showBottomSheetWithBlur(
|
||||
context: context,
|
||||
child: SuccessPublishedDietOrPlanBottomSheet(title: widget.diet.name),
|
||||
);
|
||||
await context.read<MyDietsCubit>().loadAllDiets();
|
||||
case 422:
|
||||
showErrorToast('Пожалуйста, заполните все обязательные поля для публикации');
|
||||
default:
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,35 +175,8 @@ class _MyDietWidgetState extends State<MyDietWidget> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// Верхний ряд: Удалить + Редактировать (или + Поделиться для опубликованных)
|
||||
Row(
|
||||
children: [
|
||||
// Кнопка удаления (слева)
|
||||
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(width: 6),
|
||||
// Кнопка редактирования (центр)
|
||||
Expanded(
|
||||
child: CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
@@ -206,20 +185,23 @@ class _MyDietWidgetState extends State<MyDietWidget> {
|
||||
} else if (state.selectedStateIndex == 2) {
|
||||
_suggestDiet(widget.diet);
|
||||
} else {
|
||||
_editDiet(widget.diet);
|
||||
}
|
||||
_editDiet(widget.diet, context);
|
||||
}
|
||||
},
|
||||
text: switch (state.selectedStateIndex) {
|
||||
1 => s.publish,
|
||||
2 => s.toOffer,
|
||||
_ => s.edit,
|
||||
},
|
||||
text: s.edit,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.black),
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(
|
||||
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.lightGray0),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Кнопка поделиться (справа) для опубликованных
|
||||
if (state.selectedStateIndex == 0) ...[
|
||||
const SizedBox(width: 6),
|
||||
CustomOutlinedButton(
|
||||
@@ -315,7 +297,7 @@ class _MyDietWidgetState extends State<MyDietWidget> {
|
||||
if (state.selectedStateIndex == 0) {
|
||||
_unpublishDiet(widget.diet, context);
|
||||
} else {
|
||||
_editDiet(widget.diet);
|
||||
_editDiet(widget.diet, context);
|
||||
}
|
||||
},
|
||||
text: switch (state.selectedStateIndex) {
|
||||
|
||||
@@ -21,6 +21,7 @@ class _MyDietsTabState extends State<MyDietsTab> {
|
||||
final s = S.of(context);
|
||||
if (tabTitles.isEmpty) {
|
||||
tabTitles.add(s.published);
|
||||
tabTitles.add(s.drafted);
|
||||
tabTitles.add(s.personal);
|
||||
}
|
||||
super.didChangeDependencies();
|
||||
@@ -30,29 +31,37 @@ class _MyDietsTabState extends State<MyDietsTab> {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<MyDietsCubit, MyDietsState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Container(
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: appTheme.whiteA700,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
padding: const EdgeInsets.all(4),
|
||||
return Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
...List.generate(
|
||||
2,
|
||||
(index) => Expanded(
|
||||
child: AnimatedOptionButton(
|
||||
textStyle: TextStyles.textSMedium,
|
||||
isSelected: state.selectedStateIndex == index,
|
||||
text: tabTitles[index],
|
||||
onTap: () {
|
||||
widget.additionalOnTap?.call();
|
||||
context.read<MyDietsCubit>().changeSelectedStateIndex(index);
|
||||
},
|
||||
),
|
||||
Container(
|
||||
width: 484,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: appTheme.whiteA700,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Row(
|
||||
children: [
|
||||
...List.generate(
|
||||
3,
|
||||
(index) => Expanded(
|
||||
child: AnimatedOptionButton(
|
||||
textStyle: TextStyles.textSMedium,
|
||||
isSelected: state.selectedStateIndex == index,
|
||||
text: tabTitles[index],
|
||||
onTap: () {
|
||||
widget.additionalOnTap?.call();
|
||||
context.read<MyDietsCubit>().changeSelectedStateIndex(index);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user