diff --git a/lib/features/create_diet/presentation/diet_preview_screen.dart b/lib/features/create_diet/presentation/diet_preview_screen.dart index 6c337142..94b21709 100644 --- a/lib/features/create_diet/presentation/diet_preview_screen.dart +++ b/lib/features/create_diet/presentation/diet_preview_screen.dart @@ -26,10 +26,7 @@ class DietPreviewScreen extends StatefulWidget { late final List selectedIndexes; static const name = 'createDietScreenPreview'; static const path = '/create-diet-screen/preview'; - DietPreviewScreen({ - super.key, - required this.diet, - }) { + DietPreviewScreen({super.key, required this.diet}) { selectedIndexes = List.generate(diet.dailySchedule.length, (_) => 0); } @@ -65,11 +62,7 @@ class _DietPreviewScreenState extends State { padding: const EdgeInsets.symmetric(vertical: 12) + (Platform.isIOS ? const EdgeInsets.only(bottom: 16) : EdgeInsets.zero), decoration: BoxDecoration( color: Colors.white, - border: Border( - top: BorderSide( - color: Colors.black.withValues(alpha: 0.1), - ), - ), + border: Border(top: BorderSide(color: Colors.black.withValues(alpha: 0.1))), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16), @@ -79,34 +72,16 @@ class _DietPreviewScreenState extends State { Row( children: [ Expanded( - child: SizedBox( - child: FloatingActionButton.extended( - heroTag: 'nextButtonRegistration', - highlightElevation: 0, - elevation: 0, - focusElevation: 0, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - ), - backgroundColor: appTheme.greenA700, - onPressed: () {}, - label: Text( - s.startDiet, - style: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), - ), - ), + child: BookmarkButton( + isFavorite: widget.diet.isFavorite, + onTap: () {}, + width: 52, + height: 52, + size: 24, + shape: BoxShape.circle, + color: appTheme.gray50, ), ), - const SizedBox(width: 8), - BookmarkButton( - isFavorite: widget.diet.isFavorite, - onTap: () {}, - width: 52, - height: 52, - size: 24, - shape: BoxShape.circle, - color: appTheme.gray50, - ), ], ), const SizedBox(height: 8), @@ -133,24 +108,15 @@ class _DietPreviewScreenState extends State { filled: true, border: OutlineInputBorder( borderRadius: BorderRadius.circular(16), - borderSide: const BorderSide( - color: Color(0xFFD1D1D6), - width: 1, - ), + borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(16), - borderSide: const BorderSide( - color: Color(0xFFD1D1D6), - width: 1, - ), + borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1), ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(16), - borderSide: const BorderSide( - color: Color(0xFFD1D1D6), - width: 1, - ), + borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1), ), ), ), @@ -160,17 +126,10 @@ class _DietPreviewScreenState extends State { GestureDetector( onTap: () {}, child: Container( - decoration: BoxDecoration( - color: textEditingController.text.length > 2 ? appTheme.blueA400 : appTheme.gray50, - shape: BoxShape.circle, - ), + decoration: BoxDecoration(color: textEditingController.text.length > 2 ? appTheme.blueA400 : appTheme.gray50, shape: BoxShape.circle), height: 32, width: 32, - child: Icon( - Icons.send_rounded, - size: 18, - color: textEditingController.text.length > 2 ? appTheme.whiteA700 : appTheme.black, - ), + child: Icon(Icons.send_rounded, size: 18, color: textEditingController.text.length > 2 ? appTheme.whiteA700 : appTheme.black), ), ), ], @@ -212,12 +171,7 @@ class _DietPreviewScreenState extends State { children: [ Stack( children: [ - Image.memory( - imageData, - height: 300, - width: MediaQuery.sizeOf(context).width, - fit: BoxFit.fill, - ), + Image.memory(imageData, height: 300, width: MediaQuery.sizeOf(context).width, fit: BoxFit.fill), // CachedNetworkImage( // imageUrl: baseUrl + '/storage/' + widget.diet.image, // ), @@ -233,10 +187,7 @@ class _DietPreviewScreenState extends State { children: [ SvgPicture.asset('assets/icons/eye.svg', width: 18, height: 12), const SizedBox(width: 8), - Text( - widget.diet.totalViews.toString(), - style: TextStyles.textXSSemibold.copyWith(color: appTheme.black), - ), + Text(widget.diet.totalViews.toString(), style: TextStyles.textXSSemibold.copyWith(color: appTheme.black)), ], ), const SizedBox(width: 12), @@ -252,10 +203,7 @@ class _DietPreviewScreenState extends State { colorFilter: widget.diet.wasLikedByMe ? ColorFilter.mode(appTheme.blueA400, BlendMode.srcIn) : null, ), const SizedBox(width: 8), - Text( - widget.diet.totalLikes.toString(), - style: TextStyles.textXSSemibold.copyWith(color: appTheme.black), - ), + Text(widget.diet.totalLikes.toString(), style: TextStyles.textXSSemibold.copyWith(color: appTheme.black)), ], ), ), @@ -265,10 +213,7 @@ class _DietPreviewScreenState extends State { children: [ SvgPicture.asset('assets/icons/comment2.svg', width: 13, height: 12), const SizedBox(width: 8), - Text( - widget.diet.totalComments.toString(), - style: TextStyles.textXSSemibold.copyWith(color: appTheme.black), - ), + Text(widget.diet.totalComments.toString(), style: TextStyles.textXSSemibold.copyWith(color: appTheme.black)), ], ), ], @@ -279,23 +224,15 @@ class _DietPreviewScreenState extends State { const SizedBox(height: 16), Padding( padding: const EdgeInsets.symmetric(horizontal: 16), - child: Text( - s.about_diet, - style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), - ), + child: Text(s.about_diet, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), ), const SizedBox(height: 12), - InfoRow(diet: widget.diet, type: ProductType.diet,), - ExpandableText( - text: widget.diet.details, - ), + InfoRow(diet: widget.diet, type: ProductType.diet), + ExpandableText(text: widget.diet.details), const SizedBox(height: 20), Padding( padding: const EdgeInsets.symmetric(horizontal: 16), - child: AuthorCard( - author: widget.diet.author, - title: s.diet_author, - ), + child: AuthorCard(author: widget.diet.author, title: s.diet_author), ), const SizedBox(height: 16), ], @@ -308,9 +245,7 @@ class _DietPreviewScreenState extends State { child: Center( child: Text( '${s.diet_plan}(${widget.diet.duration.toString()} ${getDayForm(widget.diet.duration, s)})', - style: TextStyles.headingXLSemibold.copyWith( - color: appTheme.black, - ), + style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), ), ), ), @@ -320,7 +255,7 @@ class _DietPreviewScreenState extends State { physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { - return _dayOfPlan(widget.diet.dailySchedule[index] ?? {}, index, s); + return _dayOfPlan(widget.diet.dailySchedule[index + 1] ?? {}, index, s); }, itemCount: widget.diet.dailySchedule.length, ), @@ -331,12 +266,7 @@ class _DietPreviewScreenState extends State { Container( padding: const EdgeInsets.symmetric(horizontal: 16), alignment: Alignment.centerLeft, - child: Text( - '0 ${getCommentForm(widget.diet.totalComments, s)}', - style: TextStyles.textMMedium.copyWith( - color: appTheme.gray500, - ), - ), + child: Text('0 ${getCommentForm(widget.diet.totalComments, s)}', style: TextStyles.textMMedium.copyWith(color: appTheme.gray500)), ), const SizedBox(height: 16), ], @@ -355,14 +285,10 @@ class _DietPreviewScreenState extends State { pressElevation: 0, showCheckmark: false, side: BorderSide.none, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - ), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), label: Text((index + 1).toString()), - labelStyle: TextStyles.textXSSemibold.copyWith( - color: index == widget.selectedIndexes[dayNumber] ? Colors.white : appTheme.gray600, - ), + labelStyle: TextStyles.textXSSemibold.copyWith(color: index == widget.selectedIndexes[dayNumber] ? Colors.white : appTheme.gray600), selected: widget.selectedIndexes[dayNumber] == index, backgroundColor: appTheme.gray100, onSelected: (bool selected) { @@ -376,9 +302,7 @@ class _DietPreviewScreenState extends State { return Padding( padding: const EdgeInsets.only(bottom: 8), child: MainBackgroundBouble( - padding: const EdgeInsets.only( - top: 16, - ), + padding: const EdgeInsets.only(top: 16), child: Column( children: [ Padding( @@ -386,31 +310,12 @@ class _DietPreviewScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - '${s.day} ${dayNumber + 1}', - style: TextStyles.headingXLSemibold.copyWith( - color: appTheme.black, - ), - ), - const Padding( - padding: EdgeInsets.symmetric(vertical: 12), - child: CustomDivider(), - ), - Text( - s.meal, - style: TextStyles.textMMedium.copyWith( - color: appTheme.black, - ), - ), + Text('${s.day} ${dayNumber + 1}', style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), + const Padding(padding: EdgeInsets.symmetric(vertical: 12), child: CustomDivider()), + Text(s.meal, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - choiceChipWidget(0), - choiceChipWidget(1), - choiceChipWidget(2), - choiceChipWidget(3), - choiceChipWidget(4), - ], + children: [choiceChipWidget(0), choiceChipWidget(1), choiceChipWidget(2), choiceChipWidget(3), choiceChipWidget(4)], ), const SizedBox(height: 8), ListView.builder( @@ -443,20 +348,10 @@ class _DietPreviewScreenState extends State { children: [ SizedBox( width: MediaQuery.sizeOf(context).width * 0.6, - child: Text( - daily.name, - style: TextStyles.textMMedium.copyWith( - color: appTheme.black, - ), - ), + child: Text(daily.name, style: TextStyles.textMMedium.copyWith(color: appTheme.black)), ), const Spacer(), - Text( - '${daily.quantity} ${getLocalizedMeasurementUnits(s, daily.portion)}', - style: TextStyles.textMSemibold.copyWith( - color: appTheme.black, - ), - ), + Text('${daily.quantity} ${getLocalizedMeasurementUnits(s, daily.portion)}', style: TextStyles.textMSemibold.copyWith(color: appTheme.black)), ], ), ); diff --git a/lib/features/create_diet/presentation/widgets/add_meal_widget.dart b/lib/features/create_diet/presentation/widgets/add_meal_widget.dart index 8f125abd..ececed87 100644 --- a/lib/features/create_diet/presentation/widgets/add_meal_widget.dart +++ b/lib/features/create_diet/presentation/widgets/add_meal_widget.dart @@ -46,21 +46,14 @@ class _AddMealWidgetState extends State { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.all(16) + - EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom, - ), + padding: const EdgeInsets.all(16) + EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ const Text( 'Добавление блюда', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w600, - color: Color(0xFF323F4B), - ), + style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Color(0xFF323F4B)), ), const SizedBox(height: 16), Row( @@ -73,21 +66,17 @@ class _AddMealWidgetState extends State { autofocus: true, hintText: 'Введите название продукта/блюда', onChanged: (query) { - EasyDebounce.debounce( - 'glossary-search', - const Duration(milliseconds: 250), - () async { + EasyDebounce.debounce('glossary-search', const Duration(milliseconds: 250), () async { + selectedGlossary = null; + if (query.isEmpty) { + glossariesList = []; selectedGlossary = null; - if (query.isEmpty) { - glossariesList = []; - selectedGlossary = null; - setState(() {}); - return; - } - glossariesList = await widget.createDietCubit.getGlossaryListByQuery(query); setState(() {}); - }, - ); + return; + } + glossariesList = await widget.createDietCubit.getGlossaryListByQuery(query); + setState(() {}); + }); }, ), ), @@ -100,22 +89,20 @@ class _AddMealWidgetState extends State { hintText: selectedGlossary == null ? '100' : selectedGlossary!.grInPortion == 0 - ? '100' - : '1', + ? '100' + : '1', suffixText: selectedGlossary == null ? 'гр' : selectedGlossary?.grInPortion == 0 - ? 'гр' - : 'шт', + ? 'гр' + : 'шт', ), ), ], ), glossariesList.isEmpty ? const SizedBox(height: 16) : const SizedBox.shrink(), Container( - constraints: const BoxConstraints( - maxHeight: 256, - ), + constraints: const BoxConstraints(maxHeight: 256), child: ListView.separated( physics: const BouncingScrollPhysics(), shrinkWrap: true, @@ -130,28 +117,12 @@ class _AddMealWidgetState extends State { setState(() {}); FocusManager.instance.primaryFocus?.nextFocus(); }, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20), - ), - title: Text( - glossariesList[i].name, - style: const TextStyle( - height: 1, - ), - ), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), + title: Text(glossariesList[i].name, style: const TextStyle(height: 1)), subtitle: glossariesList[i].grInPortion == 0 ? null - : Text( - '${glossariesList[i].grInPortion} г', - style: TextStyle( - height: 1, - color: Colors.grey.shade600, - ), - ), - trailing: Icon( - Icons.add_rounded, - color: Colors.grey.shade400, - ), + : Text('${glossariesList[i].grInPortion} г', style: TextStyle(height: 1, color: Colors.grey.shade600)), + trailing: Icon(Icons.add_rounded, color: Colors.grey.shade400), contentPadding: const EdgeInsets.only(left: 12), ); }, @@ -166,25 +137,15 @@ class _AddMealWidgetState extends State { if (widget.portionIndex != null) InkWell( onTap: () { - widget.createDietCubit.removePortion( - day: widget.dayIndex, - meal: widget.mealIndex, - portionIndex: widget.portionIndex!, - ); + widget.createDietCubit.removePortion(day: widget.dayIndex, meal: widget.mealIndex, portionIndex: widget.portionIndex!); Navigator.of(context).pop(); }, borderRadius: BorderRadius.circular(20), child: Ink( width: 52, height: 52, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), - color: const Color(0xFFF6F6F6), - ), - child: const Icon( - Icons.delete_outline_rounded, - color: Colors.red, - ), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: const Color(0xFFF6F6F6)), + child: const Icon(Icons.delete_outline_rounded, color: Colors.red), ), ), if (widget.portionIndex != null) const SizedBox(width: 8), @@ -194,18 +155,11 @@ class _AddMealWidgetState extends State { child: Ink( width: MediaQuery.of(context).size.width - (widget.portionIndex == null ? 32 : 92), height: 52, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), - color: appTheme.blueA400, - ), + decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: appTheme.blueA400), child: Center( child: Text( widget.portionIndex == null ? 'Добавить' : 'Сохранить', - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w600, - color: Colors.white, - ), + style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Colors.white), ), ), ), @@ -222,8 +176,8 @@ class _AddMealWidgetState extends State { var measurementUnits = selectedGlossary?.grInPortion == null ? Portion.pcs : selectedGlossary?.grInPortion == 0 - ? Portion.grams - : Portion.pcs; + ? Portion.grams + : Portion.pcs; final glossary = selectedGlossary; if (glossary != null) { final [calories, carbohydrates, proteins, fats] = _getCPFC(glossary, measurementUnits); @@ -235,19 +189,11 @@ class _AddMealWidgetState extends State { portion: measurementUnits, ); if (portionIndex == null) { - widget.createDietCubit.addPortion( - dayIndex: widget.dayIndex, - mealIndex: widget.mealIndex, - portion: portion, - ); + widget.createDietCubit.addPortion(dayIndex: widget.dayIndex, mealIndex: widget.mealIndex, portion: portion); } else { - widget.createDietCubit.updatePortion( - dayIndex: widget.dayIndex, - mealIndex: widget.mealIndex, - portionIndex: portionIndex, - portion: portion, - ); + widget.createDietCubit.updatePortion(dayIndex: widget.dayIndex, mealIndex: widget.mealIndex, portionIndex: portionIndex, portion: portion); } + Navigator.of(context).pop(); } else { Navigator.of(context).pop(); final newGlossary = await showModalBottomSheet( @@ -255,13 +201,8 @@ class _AddMealWidgetState extends State { useRootNavigator: true, context: context, builder: (context) => Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom, - ), - child: GlossaryModerationRequestModalWidget( - productName: productNameController.text, - diaryCubit: sl(), - ), + padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), + child: GlossaryModerationRequestModalWidget(productName: productNameController.text, diaryCubit: sl()), ), ); if (newGlossary != null) { @@ -275,18 +216,9 @@ class _AddMealWidgetState extends State { portion: measurementUnits, ); if (portionIndex == null) { - widget.createDietCubit.addPortion( - dayIndex: widget.dayIndex, - mealIndex: widget.mealIndex, - portion: portion, - ); + widget.createDietCubit.addPortion(dayIndex: widget.dayIndex, mealIndex: widget.mealIndex, portion: portion); } else { - widget.createDietCubit.updatePortion( - dayIndex: widget.dayIndex, - mealIndex: widget.mealIndex, - portion: portion, - portionIndex: portionIndex, - ); + widget.createDietCubit.updatePortion(dayIndex: widget.dayIndex, mealIndex: widget.mealIndex, portion: portion, portionIndex: portionIndex); } } }