forked from eatvio/eatvio_app
fix(calendar): Finished days fix
This commit is contained in:
@@ -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<DiaryEvent, DiaryState> {
|
||||
final DiaryRepository diaryRepository;
|
||||
|
||||
DiaryBloc({required this.diaryRepository})
|
||||
: super(const DiaryState.loading()) {
|
||||
DiaryBloc({required this.diaryRepository}) : super(const DiaryState.loading()) {
|
||||
on<LoadDiary>(loadDiary);
|
||||
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
@@ -57,29 +53,15 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45);
|
||||
final Meal currentMeal = diary.meals[0];
|
||||
|
||||
List<SelectionPopupModel> portionList = [
|
||||
SelectionPopupModel(title: "gr"),
|
||||
SelectionPopupModel(title: "pcs")
|
||||
];
|
||||
List<SelectionPopupModel> portionList = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")];
|
||||
|
||||
final Map<String, dynamic> chartData =
|
||||
await diaryRepository.getChartData(diaryID ?? 45);
|
||||
final Map<String, dynamic> dailyNutritionIntake =
|
||||
chartData['dailyNutritionIntake']!;
|
||||
final Map<String, dynamic> 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<String, dynamic> chartData = await diaryRepository.getChartData(diaryID ?? 45);
|
||||
final Map<String, dynamic> dailyNutritionIntake = chartData['dailyNutritionIntake']!;
|
||||
final Map<String, dynamic> 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<DiaryEvent, DiaryState> {
|
||||
SelectionPopupModel(title: "Прием пищи 6", id: 6),
|
||||
];
|
||||
|
||||
print(dailyNutritionRecommendations);
|
||||
print(dailyNutritionIntake);
|
||||
emit(DiaryState.loaded(
|
||||
diary: diary,
|
||||
currentMeal: currentMeal,
|
||||
@@ -117,6 +97,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
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<DiaryEvent, DiaryState> {
|
||||
}
|
||||
}
|
||||
|
||||
fetchChartValues(
|
||||
String token,
|
||||
int diaryID,
|
||||
Emitter<DiaryState> 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<int>((value) => convertToInt(value))
|
||||
.toList();
|
||||
|
||||
final consumedChartValues = responseBody['dailyNutritionIntake']
|
||||
.values
|
||||
.map<int>((value) => convertToInt(value))
|
||||
.toList();
|
||||
|
||||
print([
|
||||
recommendedChartValues,
|
||||
consumedChartValues,
|
||||
]);
|
||||
return [
|
||||
recommendedChartValues,
|
||||
consumedChartValues,
|
||||
];
|
||||
} else {
|
||||
emit(DiaryStateError(
|
||||
errorMessage: 'Ошибка при декодировании данных КБЖУ'));
|
||||
print('fail');
|
||||
return [
|
||||
[],
|
||||
[],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _changeSatiety(
|
||||
ChangeSatiety event,
|
||||
Emitter<DiaryState> emit,
|
||||
@@ -229,11 +163,9 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) 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<DiaryEvent, DiaryState> {
|
||||
) 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<DiaryEvent, DiaryState> {
|
||||
) 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<DiaryEvent, DiaryState> {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
final Map<String, List<Product>> productNutritionalValues =
|
||||
await diaryRepository.inputProduct(event.input);
|
||||
final Map<String, List<Product>> 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<DiaryEvent, DiaryState> {
|
||||
|
||||
await diaryRepository.finishDay(
|
||||
currentState.diary.id,
|
||||
currentState.wakeupController,
|
||||
currentState.retireController,
|
||||
currentState.commentController.text,
|
||||
// currentState.wakeupController,
|
||||
// currentState.retireController,
|
||||
// currentState.commentController.text,
|
||||
);
|
||||
add(LoadDiary());
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ abstract class DiaryState with _$DiaryState {
|
||||
required List<Product> 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,
|
||||
|
||||
@@ -31,8 +31,8 @@ mixin _$DiaryState {
|
||||
List<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> 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<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay wakeupController,
|
||||
TimeOfDay retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController product_nameController,
|
||||
|
||||
@@ -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<String> _options =
|
||||
state.autocompleteList.map((Product item) => item.name).toList();
|
||||
List<String> _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<String> onSelected, String option,
|
||||
DiaryStateLoaded state) {
|
||||
selectProduct(AutocompleteOnSelected<String> 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<DiaryBloc>()
|
||||
.add(RemoveImageEvent(photo.id.toString(), photo.path));
|
||||
context.read<DiaryBloc>().add(RemoveImageEvent(photo.id.toString(), photo.path));
|
||||
};
|
||||
}
|
||||
|
||||
/*_buildNutritionChart(BuildContext context, DiaryStateLoaded state) {
|
||||
final List<int> recommendedValues = state
|
||||
.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы
|
||||
final List<int> 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<DiaryBloc>().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<void> _selectWakeupTime(
|
||||
BuildContext context, DiaryStateLoaded state) async {
|
||||
Future<void> _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<DiaryBloc>().add(WakeupEvent(pickedTime));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectRetireTime(
|
||||
BuildContext context, DiaryStateLoaded state) async {
|
||||
Future<void> _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<DiaryBloc>().add(RetireEvent(pickedTime));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectMealTime(
|
||||
BuildContext context, DiaryStateLoaded state) async {
|
||||
Future<void> _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<int> recommendedValues, List<int> consumedValues) {
|
||||
bool checkConsumedValues(List<int> recommendedValues, List<int> consumedValues) {
|
||||
for (int i = 0; i < recommendedValues.length; i++) {
|
||||
if (consumedValues[i] > recommendedValues[i]) {
|
||||
// Если хотя бы одно потребленное значение превышает рекомендованное
|
||||
|
||||
Reference in New Issue
Block a user