forked from eatvio/eatvio_app
feat(my_diets): merge conflict fix
This commit is contained in:
@@ -82,12 +82,7 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key != null && key.currentContext != null) {
|
if (key != null && key.currentContext != null) {
|
||||||
Scrollable.ensureVisible(
|
Scrollable.ensureVisible(key.currentContext!, duration: const Duration(milliseconds: 500), curve: Curves.easeInOut, alignment: 0.1);
|
||||||
key.currentContext!,
|
|
||||||
duration: const Duration(milliseconds: 500),
|
|
||||||
curve: Curves.easeInOut,
|
|
||||||
alignment: 0.1,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,134 +208,131 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
child: Column(
|
child: state.isDietBeingEdited || state.isDietPublishing
|
||||||
children: [
|
? const Loader()
|
||||||
if (state.isDietBeingEdited)
|
: Column(
|
||||||
const Loader()
|
children: [
|
||||||
else
|
CustomOutlinedButton(
|
||||||
CustomOutlinedButton(
|
onPressed: () async {
|
||||||
onPressed: () async {
|
if (state.isDietPublishing) return;
|
||||||
if (state.isDietPublishing) return;
|
if (widget.diet != null && widget.isEditing == true) {
|
||||||
if (widget.diet != null && widget.isEditing == true) {
|
final dietState = state.dietState;
|
||||||
final dietState = state.dietState;
|
if (dietState == DietState.draft) {
|
||||||
if (dietState == DietState.draft) {
|
context.read<CreateDietCubit>().setDietState(DietState.active);
|
||||||
context.read<CreateDietCubit>().setDietState(DietState.active);
|
} else {
|
||||||
} else {
|
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
}
|
||||||
}
|
final result = await context.read<CreateDietCubit>().updateDiet(widget.diet!.id);
|
||||||
final result = await context.read<CreateDietCubit>().updateDiet(widget.diet!.id);
|
if (result == 'error') {
|
||||||
if (result == 'error') {
|
if (!context.mounted) return;
|
||||||
if (!context.mounted) return;
|
showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}');
|
||||||
showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}');
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (dietState == DietState.draft) {
|
||||||
if (dietState == DietState.draft) {
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
if (!context.mounted) return;
|
||||||
if (!context.mounted) return;
|
context.pop();
|
||||||
context.pop();
|
showBottomSheetWithBlur(
|
||||||
showBottomSheetWithBlur(
|
userRootNavigator: true,
|
||||||
userRootNavigator: true,
|
context: context,
|
||||||
context: context,
|
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета'),
|
||||||
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета'),
|
);
|
||||||
);
|
});
|
||||||
});
|
} else {
|
||||||
} else {
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
if (!context.mounted) return;
|
||||||
if (!context.mounted) return;
|
context.pop();
|
||||||
context.pop();
|
showBottomSheetWithBlur(
|
||||||
showBottomSheetWithBlur(
|
context: context,
|
||||||
context: context,
|
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isDrafted: true),
|
||||||
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isDrafted: true),
|
);
|
||||||
);
|
});
|
||||||
});
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
if (state.dietState != DietState.draft) {
|
||||||
if (state.dietState != DietState.draft) {
|
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
||||||
context.read<CreateDietCubit>().setDietState(DietState.draft);
|
}
|
||||||
}
|
final result = await context.read<CreateDietCubit>().createDiet();
|
||||||
final result = await context.read<CreateDietCubit>().createDiet();
|
if (result == 'error') {
|
||||||
if (result == 'error') {
|
if (!context.mounted) return;
|
||||||
if (!context.mounted) return;
|
showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}');
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
CustomOutlinedButton(
|
|
||||||
onPressed: state.isDietPublishing || state.isDietBeingEdited
|
|
||||||
? () {}
|
|
||||||
: () async {
|
|
||||||
final diet = await context.read<CreateDietCubit>().getDietForPreview();
|
|
||||||
if (diet == null) {
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
_scrollToFirstError(context.read<CreateDietCubit>().state);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!context.mounted) return;
|
|
||||||
GoRouter.of(
|
|
||||||
context,
|
|
||||||
).pushNamed(DietPreviewScreen.name, extra: {'diet': diet, 'isImageInBase64': state.dietData.imageUrl == null});
|
|
||||||
},
|
},
|
||||||
text: s.preview,
|
text: state.dietState == DietState.draft && widget.isEditing == true ? s.publish : "В черновик",
|
||||||
height: 52,
|
height: 52,
|
||||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray),
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray),
|
||||||
buttonStyle: ButtonStyle(
|
buttonStyle: ButtonStyle(
|
||||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||||
backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder),
|
backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
CustomOutlinedButton(
|
||||||
|
onPressed: state.isDietPublishing || state.isDietBeingEdited
|
||||||
|
? () {}
|
||||||
|
: () async {
|
||||||
|
final diet = await context.read<CreateDietCubit>().getDietForPreview();
|
||||||
|
if (diet == null) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
_scrollToFirstError(context.read<CreateDietCubit>().state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!context.mounted) return;
|
||||||
|
GoRouter.of(
|
||||||
|
context,
|
||||||
|
).pushNamed(DietPreviewScreen.name, extra: {'diet': diet, 'isImageInBase64': state.dietData.imageUrl == null});
|
||||||
|
},
|
||||||
|
text: s.preview,
|
||||||
|
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: () 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') {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}');
|
||||||
|
} else {
|
||||||
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
context.pop();
|
||||||
|
showBottomSheetWithBlur(
|
||||||
|
userRootNavigator: true,
|
||||||
|
context: context,
|
||||||
|
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isUpdated: true),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final result = await context.read<CreateDietCubit>().createDiet();
|
||||||
|
if (result == 'validation') {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
_scrollToFirstError(context.read<CreateDietCubit>().state);
|
||||||
|
} else if (result == 'error') {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text: widget.diet != null && widget.isEditing == true ? s.save : s.publish,
|
||||||
|
height: 52,
|
||||||
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||||
|
buttonStyle: ButtonStyle(
|
||||||
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
||||||
|
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
if (state.isDietPublishing)
|
|
||||||
const Loader()
|
|
||||||
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') {
|
|
||||||
if (!context.mounted) return;
|
|
||||||
showErrorDialog(context, title: '${s.could_not_update_diet} ${state.dietData.name}');
|
|
||||||
} else {
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
|
||||||
if (!context.mounted) return;
|
|
||||||
context.pop();
|
|
||||||
showBottomSheetWithBlur(
|
|
||||||
userRootNavigator: true,
|
|
||||||
context: context,
|
|
||||||
child: SuccessPublishedDietOrPlanBottomSheet(title: state.dietData.name ?? 'Диета', isUpdated: true),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final result = await context.read<CreateDietCubit>().createDiet();
|
|
||||||
if (result == 'validation') {
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
_scrollToFirstError(context.read<CreateDietCubit>().state);
|
|
||||||
} else if (result == 'error') {
|
|
||||||
if (!context.mounted) return;
|
|
||||||
showErrorDialog(context, title: '${s.could_not_publish_diet} ${state.dietData.name}');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
text: widget.diet != null && widget.isEditing == true ? s.save : s.publish,
|
|
||||||
height: 52,
|
|
||||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
|
||||||
buttonStyle: ButtonStyle(
|
|
||||||
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
||||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user