forked from eatvio/eatvio_app
368 lines
14 KiB
Dart
368 lines
14 KiB
Dart
import 'dart:ui';
|
|
|
|
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/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<CreateDietCubit>(),
|
|
child: const CreateDietScreenContent(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CreateDietScreenContent extends StatelessWidget {
|
|
const CreateDietScreenContent({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = S.of(context);
|
|
return BlocBuilder<CreateDietCubit, CreateDietState>(
|
|
builder: (context, state) {
|
|
if (state.published) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.pop();
|
|
showPublishSuccessBottomSheet(
|
|
context: context,
|
|
text: '${state.dietData.name ?? 'Диета'}',
|
|
);
|
|
});
|
|
} else if (state.drafted) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.pop();
|
|
showDraftSuccessBottomSheet(
|
|
context: context,
|
|
text: '${state.dietData.name ?? 'Диета'} сохраненна в черновиках',
|
|
);
|
|
});
|
|
}
|
|
|
|
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<CreateDietCubit>().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<CreateDietCubit>().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<CreateDietCubit>().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<CreateDietCubit>().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<CreateDietCubit>().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),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> showDraftSuccessBottomSheet({
|
|
required BuildContext context,
|
|
required String text,
|
|
bool hasBlur = true,
|
|
bool enableDrag = true,
|
|
}) {
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
barrierColor: appTheme.transparentBlack,
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
useSafeArea: true,
|
|
enableDrag: enableDrag,
|
|
builder: (context) => GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: BackdropFilter(
|
|
filter: ImageFilter.blur(
|
|
sigmaX: hasBlur ? 24 : 0,
|
|
sigmaY: hasBlur ? 24 : 0,
|
|
tileMode: TileMode.mirror,
|
|
),
|
|
child: SizedBox(
|
|
child: Container(
|
|
height: 200,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(20),
|
|
topRight: Radius.circular(20),
|
|
),
|
|
color: appTheme.whiteA700,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
BottomSheetHandlerBar(),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
Text(
|
|
text,
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> showPublishSuccessBottomSheet({
|
|
required BuildContext context,
|
|
required String text,
|
|
bool hasBlur = true,
|
|
bool enableDrag = true,
|
|
}) {
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
barrierColor: appTheme.transparentBlack,
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
useSafeArea: true,
|
|
enableDrag: enableDrag,
|
|
builder: (context) => GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: BackdropFilter(
|
|
filter: ImageFilter.blur(
|
|
sigmaX: hasBlur ? 24 : 0,
|
|
sigmaY: hasBlur ? 24 : 0,
|
|
tileMode: TileMode.mirror,
|
|
),
|
|
child: SizedBox(
|
|
child: Container(
|
|
height: 200,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(20),
|
|
topRight: Radius.circular(20),
|
|
),
|
|
color: appTheme.whiteA700,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
BottomSheetHandlerBar(),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
Text(
|
|
text,
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|