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:
@@ -159,9 +159,9 @@ class OtherRoutes {
|
||||
path: CreateDietScreen.path,
|
||||
name: CreateDietScreen.name,
|
||||
builder: (context, state) {
|
||||
final data = state.extra as Map<String, dynamic>;
|
||||
final diet = data['diet'] as Diet?;
|
||||
final isEditing = data['isEditing'] as bool?;
|
||||
final data = state.extra as Map<String, dynamic>?;
|
||||
final diet = data?['diet'] as Diet?;
|
||||
final isEditing = data?['isEditing'] as bool?;
|
||||
return CreateDietScreen(diet: diet, isEditing: isEditing);
|
||||
},
|
||||
),
|
||||
@@ -172,7 +172,7 @@ class OtherRoutes {
|
||||
final data = state.extra as Map<String, dynamic>;
|
||||
final diet = data['diet'] as Diet;
|
||||
final isImageInBase64 = data['isImageInBase64'] as bool;
|
||||
return DietPreviewScreen(diet: diet, isImageInBase64: isImageInBase64,);
|
||||
return DietPreviewScreen(diet: diet, isImageInBase64: isImageInBase64);
|
||||
},
|
||||
),
|
||||
GoRoute(path: RouteConstants.createPlanScreen, name: 'createPlanScreen', builder: (context, state) => const CreatePlanScreen()),
|
||||
|
||||
@@ -58,7 +58,7 @@ class InfoRow extends StatelessWidget {
|
||||
children: [
|
||||
SvgPicture.asset('assets/icons/calories.svg', width: 13.3, height: 13.3),
|
||||
const SizedBox(width: 4),
|
||||
Text('${recipe?.calories.toStringAsFixed(0) ?? '0'} ккал', style: TextStyles.textXSSemibold.copyWith(color: appTheme.black)),
|
||||
Text('${(recipe?.calories ?? 0).toStringAsFixed(0)} ккал', style: TextStyles.textXSSemibold.copyWith(color: appTheme.black)),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
@@ -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