import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/core/utils/localization_utils.dart'; import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart'; import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart'; import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/core/widgets/custom_text_form_field.dart'; import 'package:eatvio_app/core/widgets/main_background_bouble.dart'; import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_cubit.dart'; import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_state.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/day_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/diet_preview_screen.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/diet_duration_drop_down_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/diet_image_picker_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/status_drop_down_widget.dart'; import 'package:eatvio_app/features/create_diet/presentation/widgets/diet_type_choice_widget.dart'; import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; class CreateDietScreen extends StatelessWidget { static const name = 'createDietScreen'; static const path = '/create-diet-screen'; const CreateDietScreen({super.key}); @override Widget build(BuildContext context) { return BlocProvider( create: (context) => sl(), child: const CreateDietScreenContent(), ); } } class CreateDietScreenContent extends StatelessWidget { const CreateDietScreenContent({super.key}); @override Widget build(BuildContext context) { final s = S.of(context); return BlocBuilder( builder: (context, state) { if (state.published) { WidgetsBinding.instance.addPostFrameCallback((_) { context.pop(); showBottomSheetWithBlur( context: context, child: Column( children: [ SizedBox( height: 20, ), BottomSheetHandlerBar(), SizedBox( height: 20, ), Text( '${state.dietData.name ?? 'Диета'}', style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), ), Text( 'опубликованна', style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), ), SizedBox( height: 20, ), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: CustomOutlinedButton( onPressed: () { context.pop(); }, text: 'Хорошо', height: 52, buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700), buttonStyle: ButtonStyle( side: WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), ), ), ), SizedBox( height: 20, ), ], ), ); }); } else if (state.drafted) { WidgetsBinding.instance.addPostFrameCallback((_) { context.pop(); showBottomSheetWithBlur( context: context, child: Column( children: [ SizedBox( height: 20, ), BottomSheetHandlerBar(), SizedBox( height: 20, ), Text( '${state.dietData.name ?? 'Диета'} сохраненна в черновиках', textAlign: TextAlign.center, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), ), SizedBox( height: 20, ), Padding( padding: const EdgeInsets.symmetric(horizontal: 20), child: CustomOutlinedButton( onPressed: () { context.pop(); }, text: 'Хорошо', height: 52, buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700), buttonStyle: ButtonStyle( side: WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), ), ), ), SizedBox( height: 20, ), ], ), ); }); } return Scaffold( backgroundColor: appTheme.gray100, appBar: AppBar( centerTitle: true, title: Text( s.create_diet, textAlign: TextAlign.center, overflow: TextOverflow.ellipsis, softWrap: true, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), ), ), body: SingleChildScrollView( child: Column( children: [ SizedBox(height: 8), MainBackgroundBouble( padding: const EdgeInsets.symmetric(horizontal: 16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 16), CustomTextFormField( hintText: s.enter_diet_name, hasError: state.dietNameError != null, onChanged: (value) { context.read().setName(value); }, ), if (state.dietNameError != null) ...[ SizedBox( height: 4, ), CustomErrorWidget(error: state.dietNameError ?? ''), ], SizedBox(height: 12), SizedBox( height: 132, child: CustomTextFormField( hasError: state.dietDescriptionError != null, textAlignVertical: TextAlignVertical.top, maxLines: null, minLines: null, expands: true, hintText: s.enter_diet_description, onChanged: (value) { context.read().setDetails(value); }, ), ), if (state.dietDescriptionError != null) ...[ SizedBox( height: 4, ), CustomErrorWidget(error: state.dietDescriptionError ?? ''), ], SizedBox(height: 12), DietDurationDropDownWidget(), SizedBox(height: 12), StatusDropDownWidget(), SizedBox(height: 16), DietTypeChoiceWidget(), SizedBox(height: 16), DietImagePickerWidget(), SizedBox(height: 16), ], ), ), SizedBox(height: 16), MainBackgroundBouble( child: Padding( padding: const EdgeInsets.symmetric(vertical: 16.0), child: Center( child: Text( s.diet_plan + ' (${state.dietData.duration ?? 0} ' + getDayForm(state.dietData.duration ?? 0, s) + ')', style: TextStyles.headingXLSemibold.copyWith( color: appTheme.black, ), ), ), ), ), SizedBox(height: 8), ListView.separated( padding: const EdgeInsets.all(0), itemBuilder: (context, index) => DayWidget(index: index), itemCount: state.dietData.dailySchedule?.length ?? 0, shrinkWrap: true, physics: NeverScrollableScrollPhysics(), separatorBuilder: (context, index) => SizedBox(height: 8), ), SizedBox(height: 20), Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Column( children: [ CustomOutlinedButton( onPressed: () async { await context.read().publishDiet(toDraft: true); }, text: s.to_draft, height: 52, buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), buttonStyle: ButtonStyle( side: WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder), ), ), SizedBox(height: 12), CustomOutlinedButton( onPressed: () async { final diet = await context.read().getDietForPreview(); if (diet == null) return; GoRouter.of(context).pushNamed(DietPreviewScreen.name, extra: diet); }, text: s.preview, height: 52, buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.gray), buttonStyle: ButtonStyle( side: WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.dottedBorder), ), ), SizedBox(height: 12), CustomOutlinedButton( onPressed: () { context.read().publishDiet(); }, text: s.publish, height: 52, buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), buttonStyle: ButtonStyle( side: WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), ), ), ], ), ), SizedBox(height: 20), ], ), ), ); }, ); } }