forked from eatvio/eatvio_app
fix(calendar): Finished days fix
This commit is contained in:
@@ -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<CalendarModel> 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<DateTime, List<Event>>(
|
||||
equals: isSameDay,
|
||||
hashCode: getHashCode,
|
||||
)..addAll(_kEventSource);
|
||||
if (model.diary is Map<String, dynamic>) {
|
||||
final Map<String, dynamic> diary = model.diary as Map<String, dynamic>;
|
||||
|
||||
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<DateTime> 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);
|
||||
|
||||
@@ -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]) {
|
||||
// Если хотя бы одно потребленное значение превышает рекомендованное
|
||||
|
||||
@@ -189,22 +189,12 @@ class DiaryRepository {
|
||||
|
||||
Future<void> 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;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ abstract class DiaryService {
|
||||
Future<dynamic> getChart(@Path() int id);
|
||||
|
||||
@GET('/diary/product_nutritional_values/filter')
|
||||
Future<Map<String, List<Product>>> getInputProduct(
|
||||
@Query('name') String name);
|
||||
Future<Map<String, List<Product>>> getInputProduct(@Query('name') String name);
|
||||
|
||||
@POST('/diary/{diary_id}/meal/{meal_id}/satiety/fill')
|
||||
Future<Map<String, int>> sendSatietyData(
|
||||
@@ -79,9 +78,9 @@ abstract class DiaryService {
|
||||
@POST('/diary/{diary_id}/finishDay')
|
||||
Future<void> 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')
|
||||
|
||||
@@ -365,18 +365,9 @@ class _DiaryService implements DiaryService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendFinishDay(
|
||||
int diary_id,
|
||||
String wakeup,
|
||||
String retire,
|
||||
String comment,
|
||||
) async {
|
||||
Future<void> sendFinishDay(int diary_id) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{
|
||||
r'wakeUp': wakeup,
|
||||
r'retire': retire,
|
||||
r'comment': comment,
|
||||
};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
await _dio.fetch<void>(_setStreamType<void>(Options(
|
||||
|
||||
Reference in New Issue
Block a user