forked from eatvio/eatvio_app
feat(my_diets): merge conflict fixes
This commit is contained in:
@@ -180,41 +180,67 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
if (widget.diet != null && widget.isEditing == true) {
|
||||
if (state.dietState == DietState.draft) {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.active);
|
||||
if (state.isDietBeingEdited)
|
||||
const Loader()
|
||||
else
|
||||
CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
if (state.isDietPublishing) return;
|
||||
if (widget.diet != null && widget.isEditing == true) {
|
||||
final dietState = state.dietState;
|
||||
if (dietState == DietState.draft) {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.active);
|
||||
} else {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||
}
|
||||
final result = await context.read<CreateDietCubit>().updateDiet(widget.diet!.id);
|
||||
if (result == 'error') {
|
||||
if (!context.mounted) return;
|
||||
showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}');
|
||||
return;
|
||||
}
|
||||
if (dietState == DietState.draft) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (!context.mounted) return;
|
||||
context.pop();
|
||||
showBottomSheetWithBlur(
|
||||
userRootNavigator: true,
|
||||
context: context,
|
||||
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета'),
|
||||
);
|
||||
});
|
||||
} else {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (!context.mounted) return;
|
||||
context.pop();
|
||||
showBottomSheetWithBlur(
|
||||
context: context,
|
||||
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isDrafted: true),
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||
if (state.dietState != DietState.draft) {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||
}
|
||||
final result = await context.read<CreateDietCubit>().createDiet();
|
||||
if (result == 'error') {
|
||||
if (!context.mounted) return;
|
||||
showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}');
|
||||
}
|
||||
}
|
||||
final result = await context.read<CreateDietCubit>().updateDiet(widget.diet!.id);
|
||||
if (result == 'error') {
|
||||
if (!context.mounted) return;
|
||||
showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}');
|
||||
}
|
||||
} else {
|
||||
if (state.dietState != DietState.draft) {
|
||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||
}
|
||||
final result = await context.read<CreateDietCubit>().createDiet();
|
||||
if (result == 'error') {
|
||||
if (!context.mounted) return;
|
||||
showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}');
|
||||
}
|
||||
}
|
||||
},
|
||||
text: state.dietState == DietState.draft && widget.isEditing == true ? s.publish : "В черновик",
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder),
|
||||
},
|
||||
text: state.dietState == DietState.draft && widget.isEditing == true ? s.publish : "В черновик",
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
CustomOutlinedButton(
|
||||
onPressed: state.isDietPublishing
|
||||
onPressed: state.isDietPublishing || state.isDietBeingEdited
|
||||
? () {}
|
||||
: () async {
|
||||
final diet = await context.read<CreateDietCubit>().getDietForPreview();
|
||||
@@ -238,6 +264,7 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
||||
else
|
||||
CustomOutlinedButton(
|
||||
onPressed: () async {
|
||||
if (state.isDietBeingEdited) return;
|
||||
if (widget.diet != null && widget.isEditing == true) {
|
||||
final result = await context.read<CreateDietCubit>().updateDiet(widget.diet!.id);
|
||||
if (result == 'error') {
|
||||
|
||||
@@ -66,8 +66,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
imageUrl: appConfig.buildType == AppBuildType.tests ? null : imageUrl,
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(dietState: diet.state, durationIndex: durationValues.indexOf(diet.duration)));
|
||||
emit(state.copyWith(isLoading: true));
|
||||
emit(state.copyWith(isLoading: false, isDietBeingEdited: false, dietState: diet.state, durationIndex: durationValues.indexOf(diet.duration)));
|
||||
}
|
||||
|
||||
void setDetails(String text) {
|
||||
@@ -356,9 +355,12 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
}
|
||||
|
||||
Future<String?> updateDiet(int dietId) async {
|
||||
emit(state.copyWith(isDietBeingEdited: true));
|
||||
if ([DietState.active, DietState.personal].contains(state.dietState) && !_isFromValid()) {
|
||||
emit(state.copyWith(isDietBeingEdited: false));
|
||||
return 'error';
|
||||
} else if (!_isFormValidForDraft()) {
|
||||
emit(state.copyWith(isDietBeingEdited: false));
|
||||
return 'error';
|
||||
}
|
||||
|
||||
@@ -380,10 +382,12 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
details: state.dietData.details?.isEmpty ?? true ? null : state.dietData.details,
|
||||
dailySchedule: state.dietData.dailySchedule,
|
||||
);
|
||||
emit(state.copyWith(isDietBeingEdited: false));
|
||||
return null;
|
||||
} catch (e, st) {
|
||||
await Sentry.captureException(e, stackTrace: st);
|
||||
log(e.toString(), stackTrace: st);
|
||||
emit(state.copyWith(isDietBeingEdited: false));
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,11 @@ abstract class CreateDietState with _$CreateDietState {
|
||||
}) = _CreateDietState;
|
||||
|
||||
factory CreateDietState.initial() => CreateDietState(
|
||||
dailyScheduleErrors: List.filled(21, ''),
|
||||
isDietPublishing: false,
|
||||
isLoading: false,
|
||||
errorMessage: null,
|
||||
dietData: CreateDietModel(
|
||||
type: Map.fromIterable(dietTypeValues, value: (element) => false),
|
||||
),
|
||||
);
|
||||
dailyScheduleErrors: List.filled(21, ''),
|
||||
isDietPublishing: false,
|
||||
isLoading: false,
|
||||
errorMessage: null,
|
||||
isDietBeingEdited: false,
|
||||
dietData: CreateDietModel(type: Map.fromIterable(dietTypeValues, value: (element) => false)),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user