diff --git a/lib/features/calendar/presentation/pages/calendar_screen.dart b/lib/features/calendar/presentation/pages/calendar_screen.dart index 93179cb3..9dab6be2 100644 --- a/lib/features/calendar/presentation/pages/calendar_screen.dart +++ b/lib/features/calendar/presentation/pages/calendar_screen.dart @@ -1,5 +1,6 @@ // ignore_for_file: unused_local_variable +import 'package:eatvio_app/features/calendar/models/calendar_model.dart'; import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_cubit.dart'; import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart'; import 'package:eatvio_app/core/app_export.dart'; @@ -7,7 +8,6 @@ import 'package:table_calendar/table_calendar.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; -import 'dart:collection'; // ignore: must_be_immutable class CalendarScreen extends StatelessWidget { @@ -104,60 +104,48 @@ class CalendarScreen extends StatelessWidget { firstDay: DateTime.utc(2010, 10, 16), lastDay: DateTime.utc(2030, 3, 14), focusedDay: DateTime.now(), - eventLoader: (day) { - if (day.weekday == DateTime.monday) { - return [Event('Cyclic event')]; - } - - return []; - }, + startingDayOfWeek: StartingDayOfWeek.monday, + calendarBuilders: CalendarBuilders( + selectedBuilder: (context, day, focusedDay) => _buildCellDate(day, focusedDay: focusedDay, state), + defaultBuilder: (context, day, focusedDay) => _buildCellDate(day, state), + todayBuilder: (context, day, focusedDay) => _buildCellDate(day, state), + ), ), ); } } -/// Example event class. -class Event { - final String title; +Widget _buildCellDate(DateTime day, CalendarStateLoaded state, {DateTime? focusedDay}) { + final String dayString = day.toIso8601String().split('T').first; + final List calendarModels = state.calendarList; - const Event(this.title); + // Находим первую модель, соответствующую дате + final CalendarModel model = calendarModels.firstWhere((model) => model.date == dayString, orElse: () => CalendarModel(date: dayString, diary: {})); - @override - String toString() => title; -} + Color? bgclr; // Объявляем переменную bgclr здесь -/// Example events. -/// -/// Using a [LinkedHashMap] is highly recommended if you decide to use a map. -final kEvents = LinkedHashMap>( - equals: isSameDay, - hashCode: getHashCode, -)..addAll(_kEventSource); + if (model.diary is Map) { + final Map diary = model.diary as Map; -final _kEventSource = Map.fromIterable(List.generate(50, (index) => index), - key: (item) => DateTime.utc(kFirstDay.year, kFirstDay.month, item * 5), - value: (item) => List.generate( - item % 4 + 1, (index) => Event('Event $item | ${index + 1}'))) - ..addAll({ - kToday: [ - Event('Today\'s Event 1'), - Event('Today\'s Event 2'), - ], - }); + if (diary['state'] == "started") { + bgclr = Colors.grey; + } else if (diary['state'] == "finished") { + bgclr = Colors.green; + } else { + bgclr = Colors.white; + } + } else { + bgclr = Colors.white; // Значение по умолчанию, если diary не является Map + } -int getHashCode(DateTime key) { - return key.day * 1000000 + key.month * 10000 + key.year; -} - -/// Returns a list of [DateTime] objects from [first] to [last], inclusive. -List daysInRange(DateTime first, DateTime last) { - final dayCount = last.difference(first).inDays + 1; - return List.generate( - dayCount, - (index) => DateTime.utc(first.year, first.month, first.day + index), + return Container( + margin: const EdgeInsets.all(5), + alignment: Alignment.center, + decoration: BoxDecoration( + shape: (day == focusedDay) ? BoxShape.circle : BoxShape.rectangle, + color: bgclr, + borderRadius: (day == focusedDay) ? null : BorderRadius.circular(4), + ), + child: Text(day.day.toString(), style: TextStyle(color: Colors.black)), ); } - -final kToday = DateTime.now(); -final kFirstDay = DateTime(kToday.year, kToday.month - 3, kToday.day); -final kLastDay = DateTime(kToday.year, kToday.month + 3, kToday.day); diff --git a/lib/features/diary/presentation/bloc/diary_bloc.dart b/lib/features/diary/presentation/bloc/diary_bloc.dart index e6903353..8ac0e8a2 100644 --- a/lib/features/diary/presentation/bloc/diary_bloc.dart +++ b/lib/features/diary/presentation/bloc/diary_bloc.dart @@ -9,9 +9,6 @@ import 'package:flutter/material.dart'; import '/core/app_export.dart'; import 'package:image_picker/image_picker.dart'; import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart'; -import 'package:http/http.dart' as http; -import 'dart:convert'; -import 'package:flutter_dotenv/flutter_dotenv.dart'; part 'diary_event.dart'; @@ -19,8 +16,7 @@ part 'diary_event.dart'; class DiaryBloc extends Bloc { final DiaryRepository diaryRepository; - DiaryBloc({required this.diaryRepository}) - : super(const DiaryState.loading()) { + DiaryBloc({required this.diaryRepository}) : super(const DiaryState.loading()) { on(loadDiary); on(_changeSatiety); // пользователь нажимает на шкалу сытости on(_changeMood); // пользователь нажимает на шкалу настроения @@ -57,29 +53,15 @@ class DiaryBloc extends Bloc { final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45); final Meal currentMeal = diary.meals[0]; - List portionList = [ - SelectionPopupModel(title: "gr"), - SelectionPopupModel(title: "pcs") - ]; + List portionList = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")]; - final Map chartData = - await diaryRepository.getChartData(diaryID ?? 45); - final Map dailyNutritionIntake = - chartData['dailyNutritionIntake']!; - final Map dailyNutritionRecommendations = - chartData['dailyNutritionRecommendation']!; - final double ccal = dailyNutritionIntake['energy']! / - dailyNutritionRecommendations['energy']! * - 100; - final double proteins = dailyNutritionIntake['proteins']! / - dailyNutritionRecommendations['proteins']! * - 100; - final double fats = dailyNutritionIntake['fats']! / - dailyNutritionRecommendations['fats']! * - 100; - final double carbs = dailyNutritionIntake['carbohydrates']! / - dailyNutritionRecommendations['carbohydrates']! * - 100; + final Map chartData = await diaryRepository.getChartData(diaryID ?? 45); + final Map dailyNutritionIntake = chartData['dailyNutritionIntake']!; + final Map dailyNutritionRecommendations = chartData['dailyNutritionRecommendation']!; + final double ccal = dailyNutritionIntake['energy']! / dailyNutritionRecommendations['energy']! * 100; + final double proteins = dailyNutritionIntake['proteins']! / dailyNutritionRecommendations['proteins']! * 100; + final double fats = dailyNutritionIntake['fats']! / dailyNutritionRecommendations['fats']! * 100; + final double carbs = dailyNutritionIntake['carbohydrates']! / dailyNutritionRecommendations['carbohydrates']! * 100; Color getColor(double value) { if (value >= 99.1) { @@ -105,8 +87,6 @@ class DiaryBloc extends Bloc { SelectionPopupModel(title: "Прием пищи 6", id: 6), ]; - print(dailyNutritionRecommendations); - print(dailyNutritionIntake); emit(DiaryState.loaded( diary: diary, currentMeal: currentMeal, @@ -117,6 +97,8 @@ class DiaryBloc extends Bloc { chartData: chartDataCounted, selectedMood: currentMeal.mood, selectedSatiety: currentMeal.satiety, + wakeupController: TimeOfDay.now(), + retireController: TimeOfDay.now(), commentController: TextEditingController(), product_nameController: TextEditingController(), productQuantityController: TextEditingController(), @@ -137,54 +119,6 @@ class DiaryBloc extends Bloc { } } - fetchChartValues( - String token, - int diaryID, - Emitter emit, - ) async { - final responseChart = await http.get( - Uri.parse( - dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/dailyNutritionData/', - ), - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer $token', - }, - ); - - if (responseChart.statusCode == 200) { - final responseBody = jsonDecode(responseChart.body); - print(responseBody); - final recommendedChartValues = - responseBody['dailyNutritionRecommendation'] - .values - .map((value) => convertToInt(value)) - .toList(); - - final consumedChartValues = responseBody['dailyNutritionIntake'] - .values - .map((value) => convertToInt(value)) - .toList(); - - print([ - recommendedChartValues, - consumedChartValues, - ]); - return [ - recommendedChartValues, - consumedChartValues, - ]; - } else { - emit(DiaryStateError( - errorMessage: 'Ошибка при декодировании данных КБЖУ')); - print('fail'); - return [ - [], - [], - ]; - } - } - Future _changeSatiety( ChangeSatiety event, Emitter emit, @@ -229,11 +163,9 @@ class DiaryBloc extends Bloc { ) async { if (state is DiaryStateLoaded) { var currentState = state as DiaryStateLoaded; - var updatedState = - currentState.copyWith(wakeupController: event.selectedTime); + var updatedState = currentState.copyWith(wakeupController: event.selectedTime); final DateFormat formatter = DateFormat('HH:mm'); - final String wakeupString = formatter.format(DateTime( - 2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute)); + final String wakeupString = formatter.format(DateTime(2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute)); await diaryRepository.changeWakeup( currentState.diary.id, wakeupString, @@ -248,11 +180,9 @@ class DiaryBloc extends Bloc { ) async { if (state is DiaryStateLoaded) { var currentState = state as DiaryStateLoaded; - var updatedState = - currentState.copyWith(retireController: event.selectedTime); + var updatedState = currentState.copyWith(retireController: event.selectedTime); final DateFormat formatter = DateFormat('HH:mm'); - final String retireString = formatter.format(DateTime( - 2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute)); + final String retireString = formatter.format(DateTime(2022, 1, 1, event.selectedTime.hour, event.selectedTime.minute)); await diaryRepository.changeRetire( currentState.diary.id, retireString, @@ -278,8 +208,7 @@ class DiaryBloc extends Bloc { ) async { if (state is DiaryStateLoaded) { final currentState = state as DiaryStateLoaded; - final Meal meal = currentState.diary.meals - .firstWhere((meal) => meal.type == event.value.id); + final Meal meal = currentState.diary.meals.firstWhere((meal) => meal.type == event.value.id); DiaryStateLoaded updatedState = currentState.copyWith( currentMeal: meal, portions: meal.portions, @@ -298,12 +227,10 @@ class DiaryBloc extends Bloc { if (state is DiaryStateLoaded) { var currentState = state as DiaryStateLoaded; - final Map> productNutritionalValues = - await diaryRepository.inputProduct(event.input); + final Map> productNutritionalValues = await diaryRepository.inputProduct(event.input); var updatedState = currentState.copyWith( product_nameController: TextEditingController(text: event.input), - autocompleteList: - productNutritionalValues['product_nutritional_value'] ?? [], + autocompleteList: productNutritionalValues['product_nutritional_value'] ?? [], ); if (event.input.length > 3) { updatedState = updatedState.copyWith(moderationExpanded: true); @@ -449,9 +376,9 @@ class DiaryBloc extends Bloc { await diaryRepository.finishDay( currentState.diary.id, - currentState.wakeupController, - currentState.retireController, - currentState.commentController.text, + // currentState.wakeupController, + // currentState.retireController, + // currentState.commentController.text, ); add(LoadDiary()); } diff --git a/lib/features/diary/presentation/bloc/diary_state.dart b/lib/features/diary/presentation/bloc/diary_state.dart index 6feb5f14..91565766 100644 --- a/lib/features/diary/presentation/bloc/diary_state.dart +++ b/lib/features/diary/presentation/bloc/diary_state.dart @@ -26,8 +26,8 @@ abstract class DiaryState with _$DiaryState { required List autocompleteList, required Meal currentMeal, required SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + required TimeOfDay wakeupController, + required TimeOfDay retireController, TimeOfDay? mealTimeController, required TextEditingController commentController, required TextEditingController product_nameController, diff --git a/lib/features/diary/presentation/bloc/diary_state.freezed.dart b/lib/features/diary/presentation/bloc/diary_state.freezed.dart index deda8724..a8cf8f18 100644 --- a/lib/features/diary/presentation/bloc/diary_state.freezed.dart +++ b/lib/features/diary/presentation/bloc/diary_state.freezed.dart @@ -31,8 +31,8 @@ mixin _$DiaryState { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -68,8 +68,8 @@ mixin _$DiaryState { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -105,8 +105,8 @@ mixin _$DiaryState { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -224,8 +224,8 @@ class _$DiaryStateImpl implements _DiaryState { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -264,8 +264,8 @@ class _$DiaryStateImpl implements _DiaryState { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -304,8 +304,8 @@ class _$DiaryStateImpl implements _DiaryState { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -425,8 +425,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -465,8 +465,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -505,8 +505,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -592,8 +592,8 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -636,8 +636,8 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res> Object? autocompleteList = null, Object? currentMeal = null, Object? portionController = null, - Object? wakeupController = freezed, - Object? retireController = freezed, + Object? wakeupController = null, + Object? retireController = null, Object? mealTimeController = freezed, Object? commentController = null, Object? product_nameController = null, @@ -696,14 +696,14 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res> ? _value.portionController : portionController // ignore: cast_nullable_to_non_nullable as SelectionPopupModel, - wakeupController: freezed == wakeupController + wakeupController: null == wakeupController ? _value.wakeupController : wakeupController // ignore: cast_nullable_to_non_nullable - as TimeOfDay?, - retireController: freezed == retireController + as TimeOfDay, + retireController: null == retireController ? _value.retireController : retireController // ignore: cast_nullable_to_non_nullable - as TimeOfDay?, + as TimeOfDay, mealTimeController: freezed == mealTimeController ? _value.mealTimeController : mealTimeController // ignore: cast_nullable_to_non_nullable @@ -802,8 +802,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { required final List autocompleteList, required this.currentMeal, required this.portionController, - this.wakeupController, - this.retireController, + required this.wakeupController, + required this.retireController, this.mealTimeController, required this.commentController, required this.product_nameController, @@ -888,9 +888,9 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { @override final SelectionPopupModel portionController; @override - final TimeOfDay? wakeupController; + final TimeOfDay wakeupController; @override - final TimeOfDay? retireController; + final TimeOfDay retireController; @override final TimeOfDay? mealTimeController; @override @@ -1052,8 +1052,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -1120,8 +1120,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -1188,8 +1188,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -1294,8 +1294,8 @@ abstract class DiaryStateLoaded implements DiaryState { required final List autocompleteList, required final Meal currentMeal, required final SelectionPopupModel portionController, - final TimeOfDay? wakeupController, - final TimeOfDay? retireController, + required final TimeOfDay wakeupController, + required final TimeOfDay retireController, final TimeOfDay? mealTimeController, required final TextEditingController commentController, required final TextEditingController product_nameController, @@ -1323,8 +1323,8 @@ abstract class DiaryStateLoaded implements DiaryState { List get autocompleteList; Meal get currentMeal; SelectionPopupModel get portionController; - TimeOfDay? get wakeupController; - TimeOfDay? get retireController; + TimeOfDay get wakeupController; + TimeOfDay get retireController; TimeOfDay? get mealTimeController; TextEditingController get commentController; TextEditingController get product_nameController; @@ -1425,8 +1425,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -1465,8 +1465,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, @@ -1505,8 +1505,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError { List autocompleteList, Meal currentMeal, SelectionPopupModel portionController, - TimeOfDay? wakeupController, - TimeOfDay? retireController, + TimeOfDay wakeupController, + TimeOfDay retireController, TimeOfDay? mealTimeController, TextEditingController commentController, TextEditingController product_nameController, diff --git a/lib/features/diary/presentation/pages/diary_screen.dart b/lib/features/diary/presentation/pages/diary_screen.dart index 53937a94..8be9be46 100644 --- a/lib/features/diary/presentation/pages/diary_screen.dart +++ b/lib/features/diary/presentation/pages/diary_screen.dart @@ -278,9 +278,7 @@ class DiaryScreen extends StatelessWidget { borderRadius: BorderRadiusStyle.roundedBorder5, ), child: Center( - child: CircularProgressIndicator( - color: appTheme - .blueGray300), // Замените на свой прелоадер при необходимости + child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости ), ), ], @@ -304,8 +302,7 @@ class DiaryScreen extends StatelessWidget { _buildMeal(BuildContext context, DiaryStateLoaded state) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; - List _options = - state.autocompleteList.map((Product item) => item.name).toList(); + List _options = state.autocompleteList.map((Product item) => item.name).toList(); FocusNode focusNodeName = FocusNode(); return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -349,9 +346,7 @@ class DiaryScreen extends StatelessWidget { onTap: () => _selectMealTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: state.mealTimeController - ?.format(context) - .toString(), + hintText: state.mealTimeController?.format(context).toString(), autofocus: false, ), ), @@ -487,9 +482,7 @@ class DiaryScreen extends StatelessWidget { SizedBox(height: 30.v), _buildAddProduct(context, state), SizedBox(height: 30.v), - ...state.portions - .map((portion) => _buildProduct(context, portion)) - .toList(), + ...state.portions.map((portion) => _buildProduct(context, portion)).toList(), SizedBox(height: 30.v), _buildCarousel(context, state), SizedBox(height: 20.v), @@ -638,8 +631,7 @@ class DiaryScreen extends StatelessWidget { popDialog(BuildContext dialogContext) { return () { - Navigator.of(dialogContext) - .pop(); // Dismiss the dialog on Cancel button press + Navigator.of(dialogContext).pop(); // Dismiss the dialog on Cancel button press }; } @@ -649,8 +641,7 @@ class DiaryScreen extends StatelessWidget { }; } - selectProduct(AutocompleteOnSelected onSelected, String option, - DiaryStateLoaded state) { + selectProduct(AutocompleteOnSelected onSelected, String option, DiaryStateLoaded state) { state.product_nameController.text = option; return () { onSelected(option); @@ -718,9 +709,7 @@ class DiaryScreen extends StatelessWidget { top: 5.v, ), child: Text( - portion.product_name.length > 8 - ? portion.product_name.substring(0, 8) - : portion.product_name, + portion.product_name.length > 8 ? portion.product_name.substring(0, 8) : portion.product_name, style: CustomTextStyles.titleMedium16, ), ), @@ -792,234 +781,10 @@ class DiaryScreen extends StatelessWidget { removePhoto(BuildContext context, Photo photo) { return () { - context - .read() - .add(RemoveImageEvent(photo.id.toString(), photo.path)); + context.read().add(RemoveImageEvent(photo.id.toString(), photo.path)); }; } - /*_buildNutritionChart(BuildContext context, DiaryStateLoaded state) { - final List recommendedValues = state - .recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы - final List consumedValues = state.consumedChartValues; // - return Container( - margin: EdgeInsets.symmetric(horizontal: 16.h), - padding: EdgeInsets.symmetric( - horizontal: 10.h, - vertical: 16.v, - ), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: const BorderRadius.all(Radius.circular(12)), - boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.5), - spreadRadius: 2, - blurRadius: 5, - offset: Offset(0, 3), - ), - ], - ), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox(height: 3.v), - Text( - "Ваш КБЖУ", - style: theme.textTheme.titleMedium, - ), - SizedBox(height: 8.v), - Text( - "От дневной суточной нормы", - style: CustomTextStyles.bodyMediumBluegray800, - ), - SizedBox(height: 19.v), - Align( - alignment: Alignment.centerRight, - child: Padding( - padding: EdgeInsets.only( - left: 30.h, - right: 12.h, - ), - child: AspectRatio( - aspectRatio: 1.5, - child: BarChart( - BarChartData( - alignment: BarChartAlignment.spaceAround, - barTouchData: BarTouchData(enabled: false), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - //getTitlesWidget: (value, meta) => newMethod(value), - ), - ), - ), - borderData: FlBorderData(show: false), - barGroups: [ - BarChartGroupData( - x: 0, - barRods: [ - BarChartRodData( - toY: consumedValues[0] / recommendedValues[0] * 100, - color: checkConsumedValues( - [recommendedValues[0]], [consumedValues[1]]) - ? Colors.red - : Colors.blue, - ), - ], - ), - BarChartGroupData( - x: 1, - barRods: [ - BarChartRodData( - toY: consumedValues[1] / recommendedValues[1] * 100, - color: checkConsumedValues( - [recommendedValues[1]], [consumedValues[1]]) - ? Colors.red - : Colors.blue, - ), - ], - ), - BarChartGroupData( - x: 2, - barRods: [ - BarChartRodData( - toY: consumedValues[2] / recommendedValues[2] * 100, - color: checkConsumedValues( - [recommendedValues[2]], [consumedValues[2]]) - ? Colors.red - : Colors.blue, - ), - ], - ), - BarChartGroupData( - x: 3, - barRods: [ - BarChartRodData( - toY: consumedValues[3] / recommendedValues[3] * 100, - color: checkConsumedValues( - [recommendedValues[3]], [consumedValues[3]]) - ? Colors.red - : Colors.blue, - ), - ], - ), - ], - ), - ), - ), - ), - ), - SizedBox(height: 8.v), - SizedBox(height: 2.v), - Padding( - padding: EdgeInsets.only( - left: 10.h, - right: 2.h, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "Калорий", - style: theme.textTheme.bodySmall, - ), - Padding( - padding: EdgeInsets.only( - left: 25.h, - bottom: 11.v, - ), - child: Text( - "Белков", - style: theme.textTheme.bodySmall, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 19.h, - bottom: 11.v, - ), - child: Text( - "Жиров", - style: theme.textTheme.bodySmall, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 14.h, - bottom: 11.v, - ), - child: Text( - "Углеводов", - style: theme.textTheme.bodySmall, - ), - ), - ], - ), - ), - SizedBox(height: 2.v), - Padding( - padding: EdgeInsets.only( - left: 10.h, - right: 2.h, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "${consumedValues[0].toInt()} из ${recommendedValues[0].toInt()}", - style: theme.textTheme.bodySmall, - ), - Padding( - padding: EdgeInsets.only( - left: 25.h, - bottom: 11.v, - ), - child: Text( - "${consumedValues[1].toInt()} из ${recommendedValues[1].toInt()}", - style: theme.textTheme.bodySmall, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 19.h, - bottom: 11.v, - ), - child: Text( - "${consumedValues[2].toInt()} из ${recommendedValues[2].toInt()}", - style: theme.textTheme.bodySmall, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 14.h, - bottom: 11.v, - ), - child: Text( - "${consumedValues[3].toInt()} из ${recommendedValues[3].toInt()}", - style: theme.textTheme.bodySmall, - ), - ), - ], - ), - ), - SizedBox(height: 19.v), - if (checkConsumedValues(recommendedValues, consumedValues)) - Text( - "*Превышенная суточная норма", - style: theme.textTheme.labelLarge, - ), - ], - ), - ); - }*/ - - /// Section Widget _buildComment(BuildContext context, DiaryStateLoaded state) { return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -1094,9 +859,7 @@ class DiaryScreen extends StatelessWidget { r"Подъем \ отход ко сну", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.wakeupExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), + Icon(state.wakeupExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], ), ), @@ -1110,8 +873,7 @@ class DiaryScreen extends StatelessWidget { onTap: () => _selectWakeupTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: - state.wakeupController?.format(context).toString(), + hintText: state.wakeupController.format(context).toString(), prefix: Icon(Icons.sunny), autofocus: false, ), @@ -1122,8 +884,7 @@ class DiaryScreen extends StatelessWidget { onTap: () => _selectRetireTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: - state.retireController?.format(context).toString(), + hintText: state.retireController.format(context).toString(), prefix: Icon(Icons.bed), autofocus: false, ), @@ -1170,8 +931,7 @@ class DiaryScreen extends StatelessWidget { }; } - Function() sendFinishDayData( - BuildContext dialogContext, BuildContext context) { + Function() sendFinishDayData(BuildContext dialogContext, BuildContext context) { return () { closeDialog(dialogContext); context.read().add(FinishDay()); @@ -1214,9 +974,7 @@ class DiaryScreen extends StatelessWidget { "Ваше настроение после приема пищи", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.moodExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), + Icon(state.moodExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], ), ), @@ -1276,30 +1034,27 @@ class DiaryScreen extends StatelessWidget { }; } - Future _selectWakeupTime( - BuildContext context, DiaryStateLoaded state) async { + Future _selectWakeupTime(BuildContext context, DiaryStateLoaded state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, - initialTime: state.wakeupController ?? TimeOfDay.now(), + initialTime: state.wakeupController, ); if (pickedTime != null && pickedTime != state.wakeupController) { context.read().add(WakeupEvent(pickedTime)); } } - Future _selectRetireTime( - BuildContext context, DiaryStateLoaded state) async { + Future _selectRetireTime(BuildContext context, DiaryStateLoaded state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, - initialTime: state.retireController ?? TimeOfDay.now(), + initialTime: state.retireController, ); if (pickedTime != null && pickedTime != state.retireController) { context.read().add(RetireEvent(pickedTime)); } } - Future _selectMealTime( - BuildContext context, DiaryStateLoaded state) async { + Future _selectMealTime(BuildContext context, DiaryStateLoaded state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, initialTime: state.mealTimeController ?? TimeOfDay.now(), @@ -1310,8 +1065,7 @@ class DiaryScreen extends StatelessWidget { } } -bool checkConsumedValues( - List recommendedValues, List consumedValues) { +bool checkConsumedValues(List recommendedValues, List consumedValues) { for (int i = 0; i < recommendedValues.length; i++) { if (consumedValues[i] > recommendedValues[i]) { // Если хотя бы одно потребленное значение превышает рекомендованное diff --git a/lib/features/diary/repositories/diary_repository.dart b/lib/features/diary/repositories/diary_repository.dart index 56c9fbd6..599c0810 100644 --- a/lib/features/diary/repositories/diary_repository.dart +++ b/lib/features/diary/repositories/diary_repository.dart @@ -189,22 +189,12 @@ class DiaryRepository { Future finishDay( int diaryID, - TimeOfDay? wakeup, - TimeOfDay? retire, - String? comment, ) async { try { - final formatter = DateFormat('HH:mm'); - final wakeupString = - formatter.format(DateTime(2022, 1, 1, wakeup!.hour, wakeup.minute)); - final retireString = - formatter.format(DateTime(2022, 1, 1, retire!.hour, retire.minute)); - await diaryService.sendFinishDay( - diaryID, - wakeupString, - retireString, - comment ?? " ", - ); + /*final formatter = DateFormat('HH:mm'); + final wakeupString = formatter.format(DateTime(2022, 1, 1, wakeup.hour, wakeup.minute)); + final retireString = formatter.format(DateTime(2022, 1, 1, retire.hour, retire.minute));*/ + await diaryService.sendFinishDay(diaryID); } catch (e) { rethrow; } diff --git a/lib/features/diary/services/diary_service.dart b/lib/features/diary/services/diary_service.dart index 125db491..bf9a8900 100644 --- a/lib/features/diary/services/diary_service.dart +++ b/lib/features/diary/services/diary_service.dart @@ -22,8 +22,7 @@ abstract class DiaryService { Future getChart(@Path() int id); @GET('/diary/product_nutritional_values/filter') - Future>> getInputProduct( - @Query('name') String name); + Future>> getInputProduct(@Query('name') String name); @POST('/diary/{diary_id}/meal/{meal_id}/satiety/fill') Future> sendSatietyData( @@ -79,9 +78,9 @@ abstract class DiaryService { @POST('/diary/{diary_id}/finishDay') Future sendFinishDay( @Path() int diary_id, - @Query('wakeUp') String wakeup, - @Query('retire') String retire, - @Query('comment') String comment, + //@Query('wakeUp') String wakeup, + //@Query('retire') String retire, + //@Query('comment') String comment, ); @DELETE('/diary/{diary_id}/meal/{meal_id}/portions/{portion_id}/delete') diff --git a/lib/features/diary/services/diary_service.g.dart b/lib/features/diary/services/diary_service.g.dart index 01a34881..91e048e5 100644 --- a/lib/features/diary/services/diary_service.g.dart +++ b/lib/features/diary/services/diary_service.g.dart @@ -365,18 +365,9 @@ class _DiaryService implements DiaryService { } @override - Future sendFinishDay( - int diary_id, - String wakeup, - String retire, - String comment, - ) async { + Future sendFinishDay(int diary_id) async { final _extra = {}; - final queryParameters = { - r'wakeUp': wakeup, - r'retire': retire, - r'comment': comment, - }; + final queryParameters = {}; final _headers = {}; const Map? _data = null; await _dio.fetch(_setStreamType(Options(