forked from eatvio/eatvio_app
Merge branch 'main' of ssh://10.55.5.123:222/misha/eatvio_app into issue-911
This commit is contained in:
@@ -274,7 +274,7 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
||||
: () async {
|
||||
final diet = await context.read<CreateDietCubit>().getDietForPreview();
|
||||
if (diet == null) {
|
||||
// ignore: use_build_context_synchronously
|
||||
if (!context.mounted) return;
|
||||
_scrollToFirstError(context.read<CreateDietCubit>().state);
|
||||
return;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ class _CreateDietScreenContentState extends State<CreateDietScreenContent> {
|
||||
} else {
|
||||
final result = await context.read<CreateDietCubit>().createDiet();
|
||||
if (result == 'validation') {
|
||||
// ignore: use_build_context_synchronously
|
||||
if (!context.mounted) return;
|
||||
_scrollToFirstError(context.read<CreateDietCubit>().state);
|
||||
} else if (result == 'error') {
|
||||
if (!context.mounted) return;
|
||||
|
||||
@@ -199,11 +199,17 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const int _maxImageBytesForBase64 = 5 * 1024 * 1024;
|
||||
|
||||
Future<Diet?> getDietForPreview() async {
|
||||
if (!_isFormValidForDraft()) return null;
|
||||
final authorProfile = await profileRepository.getMyProfile();
|
||||
final imageBytes = (await state.dietData.image?.readAsBytes()) ?? <int>[];
|
||||
String image = base64.encode(imageBytes);
|
||||
String image = '';
|
||||
if (imageBytes.isNotEmpty && imageBytes.length <= _maxImageBytesForBase64) {
|
||||
image = base64.encode(imageBytes);
|
||||
}
|
||||
if (image.isEmpty && state.dietData.imageUrl != null) {
|
||||
image = state.dietData.imageUrl ?? '';
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ class _DietPreviewScreenState extends State<DietPreviewScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
|
||||
@@ -61,8 +61,10 @@ class _MyDietWidgetState extends State<MyDietWidget> {
|
||||
child: SuccessPublishedDietOrPlanBottomSheet(title: widget.diet.name),
|
||||
);
|
||||
await context.read<MyDietsCubit>().loadAllDiets();
|
||||
break;
|
||||
case 422:
|
||||
showErrorToast('Пожалуйста, заполните все обязательные поля для публикации');
|
||||
break;
|
||||
default:
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user