fix(diary): Remove portion API call fixed
This commit is contained in:
@@ -7,7 +7,7 @@ part 'portion.g.dart';
|
||||
class Portion with _$Portion {
|
||||
const factory Portion({
|
||||
required int id,
|
||||
required String productName,
|
||||
required String product_name,
|
||||
required int quantity,
|
||||
required String portion,
|
||||
}) = _Portion;
|
||||
|
||||
@@ -21,7 +21,7 @@ Portion _$PortionFromJson(Map<String, dynamic> json) {
|
||||
/// @nodoc
|
||||
mixin _$Portion {
|
||||
int get id => throw _privateConstructorUsedError;
|
||||
String get productName => throw _privateConstructorUsedError;
|
||||
String get product_name => throw _privateConstructorUsedError;
|
||||
int get quantity => throw _privateConstructorUsedError;
|
||||
String get portion => throw _privateConstructorUsedError;
|
||||
|
||||
@@ -35,7 +35,7 @@ abstract class $PortionCopyWith<$Res> {
|
||||
factory $PortionCopyWith(Portion value, $Res Function(Portion) then) =
|
||||
_$PortionCopyWithImpl<$Res, Portion>;
|
||||
@useResult
|
||||
$Res call({int id, String productName, int quantity, String portion});
|
||||
$Res call({int id, String product_name, int quantity, String portion});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -52,7 +52,7 @@ class _$PortionCopyWithImpl<$Res, $Val extends Portion>
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? productName = null,
|
||||
Object? product_name = null,
|
||||
Object? quantity = null,
|
||||
Object? portion = null,
|
||||
}) {
|
||||
@@ -61,9 +61,9 @@ class _$PortionCopyWithImpl<$Res, $Val extends Portion>
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
productName: null == productName
|
||||
? _value.productName
|
||||
: productName // ignore: cast_nullable_to_non_nullable
|
||||
product_name: null == product_name
|
||||
? _value.product_name
|
||||
: product_name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
quantity: null == quantity
|
||||
? _value.quantity
|
||||
@@ -84,7 +84,7 @@ abstract class _$$PortionImplCopyWith<$Res> implements $PortionCopyWith<$Res> {
|
||||
__$$PortionImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({int id, String productName, int quantity, String portion});
|
||||
$Res call({int id, String product_name, int quantity, String portion});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -99,7 +99,7 @@ class __$$PortionImplCopyWithImpl<$Res>
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? productName = null,
|
||||
Object? product_name = null,
|
||||
Object? quantity = null,
|
||||
Object? portion = null,
|
||||
}) {
|
||||
@@ -108,9 +108,9 @@ class __$$PortionImplCopyWithImpl<$Res>
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
productName: null == productName
|
||||
? _value.productName
|
||||
: productName // ignore: cast_nullable_to_non_nullable
|
||||
product_name: null == product_name
|
||||
? _value.product_name
|
||||
: product_name // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
quantity: null == quantity
|
||||
? _value.quantity
|
||||
@@ -129,7 +129,7 @@ class __$$PortionImplCopyWithImpl<$Res>
|
||||
class _$PortionImpl implements _Portion {
|
||||
const _$PortionImpl(
|
||||
{required this.id,
|
||||
required this.productName,
|
||||
required this.product_name,
|
||||
required this.quantity,
|
||||
required this.portion});
|
||||
|
||||
@@ -139,7 +139,7 @@ class _$PortionImpl implements _Portion {
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
final String productName;
|
||||
final String product_name;
|
||||
@override
|
||||
final int quantity;
|
||||
@override
|
||||
@@ -147,7 +147,7 @@ class _$PortionImpl implements _Portion {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Portion(id: $id, productName: $productName, quantity: $quantity, portion: $portion)';
|
||||
return 'Portion(id: $id, product_name: $product_name, quantity: $quantity, portion: $portion)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -156,8 +156,8 @@ class _$PortionImpl implements _Portion {
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PortionImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.productName, productName) ||
|
||||
other.productName == productName) &&
|
||||
(identical(other.product_name, product_name) ||
|
||||
other.product_name == product_name) &&
|
||||
(identical(other.quantity, quantity) ||
|
||||
other.quantity == quantity) &&
|
||||
(identical(other.portion, portion) || other.portion == portion));
|
||||
@@ -166,7 +166,7 @@ class _$PortionImpl implements _Portion {
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, id, productName, quantity, portion);
|
||||
Object.hash(runtimeType, id, product_name, quantity, portion);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@@ -185,7 +185,7 @@ class _$PortionImpl implements _Portion {
|
||||
abstract class _Portion implements Portion {
|
||||
const factory _Portion(
|
||||
{required final int id,
|
||||
required final String productName,
|
||||
required final String product_name,
|
||||
required final int quantity,
|
||||
required final String portion}) = _$PortionImpl;
|
||||
|
||||
@@ -194,7 +194,7 @@ abstract class _Portion implements Portion {
|
||||
@override
|
||||
int get id;
|
||||
@override
|
||||
String get productName;
|
||||
String get product_name;
|
||||
@override
|
||||
int get quantity;
|
||||
@override
|
||||
|
||||
@@ -9,7 +9,7 @@ part of 'portion.dart';
|
||||
_$PortionImpl _$$PortionImplFromJson(Map<String, dynamic> json) =>
|
||||
_$PortionImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
productName: json['productName'] as String,
|
||||
product_name: json['product_name'] as String,
|
||||
quantity: (json['quantity'] as num).toInt(),
|
||||
portion: json['portion'] as String,
|
||||
);
|
||||
@@ -17,7 +17,7 @@ _$PortionImpl _$$PortionImplFromJson(Map<String, dynamic> json) =>
|
||||
Map<String, dynamic> _$$PortionImplToJson(_$PortionImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'productName': instance.productName,
|
||||
'product_name': instance.product_name,
|
||||
'quantity': instance.quantity,
|
||||
'portion': instance.portion,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:eatvio_app/features/diary/models/product.dart';
|
||||
import 'package:eatvio_app/features/diary/repositories/diary_repository.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -82,7 +83,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
selectedMood: currentMeal.mood,
|
||||
selectedSatiety: currentMeal.satiety,
|
||||
commentController: TextEditingController(),
|
||||
productNameController: TextEditingController(),
|
||||
product_nameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
caloriesController: TextEditingController(),
|
||||
fatsController: TextEditingController(),
|
||||
@@ -259,15 +260,14 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
Emitter<DiaryState> emit,
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
//var currentState = state as DiaryStateLoaded;
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
print(await diaryRepository.inputProduct(event.input));
|
||||
final Map<String, List<Product>> productNutritionalValues =
|
||||
await diaryRepository.inputProduct(event.input);
|
||||
// Create a new controller with the input text and update the autocomplete list
|
||||
/*var updatedState = currentState.copyWith(
|
||||
productNameController: TextEditingController(text: event.input),
|
||||
autocompleteList: productNutritionalValues.map((product) => product['name']).toList(),
|
||||
var updatedState = currentState.copyWith(
|
||||
product_nameController: TextEditingController(text: event.input),
|
||||
autocompleteList:
|
||||
productNutritionalValues['product_nutritional_value'] ?? [],
|
||||
);
|
||||
if (event.input.length > 3) {
|
||||
updatedState = updatedState.copyWith(moderationExpanded: true);
|
||||
@@ -275,7 +275,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
updatedState = updatedState.copyWith(moderationExpanded: false);
|
||||
}
|
||||
|
||||
emit(updatedState); */
|
||||
emit(updatedState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,16 +331,25 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
print(currentState.diary.id);
|
||||
print(currentState.currentMeal.id);
|
||||
print(currentState.product_nameController.text);
|
||||
print(currentState.portionController.title);
|
||||
print(currentState.productQuantityController.text);
|
||||
|
||||
await diaryRepository.addPortion(
|
||||
Map<String, Portion> data = await diaryRepository.addPortion(
|
||||
currentState.diary.id,
|
||||
currentState.currentMeal.id,
|
||||
currentState.productNameController.text,
|
||||
currentState.portionController.value,
|
||||
currentState.product_nameController.text,
|
||||
currentState.portionController.title,
|
||||
int.parse(currentState.productQuantityController.text),
|
||||
);
|
||||
List<Portion> newPortions = currentState.portions;
|
||||
|
||||
emit(currentState.copyWith(isAdded: true));
|
||||
final Portion newPortion = data['portion'] ??
|
||||
new Portion(id: 1, portion: 'gr', product_name: '1', quantity: 1);
|
||||
newPortions.add(newPortion);
|
||||
emit(currentState.copyWith(isAdded: true, portions: newPortions));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,45 +359,14 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
int? mealId =
|
||||
currentState.currentMeal.id; // Rename id to mealId for clarity
|
||||
|
||||
var response = await sendRemovePortion(
|
||||
event.portionId,
|
||||
mealId,
|
||||
await diaryRepository.removePortion(
|
||||
currentState.diary.id,
|
||||
currentState.currentMeal.id,
|
||||
event.portionId,
|
||||
);
|
||||
|
||||
if (response.statusCode == 204) {
|
||||
await reloadScreen(event, emit);
|
||||
} else {
|
||||
print(
|
||||
'Failed to add portion. Status Code: ${response.statusCode} ${response.body}',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<http.Response> sendRemovePortion(
|
||||
int? portionID,
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/portions/$portionID/delete';
|
||||
|
||||
var response = await http.delete(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
encoding: utf8,
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
FutureOr<void> _removeImage(
|
||||
RemoveImageEvent event,
|
||||
Emitter<DiaryState> emit,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/models/photo.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:eatvio_app/features/diary/models/product.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
@@ -18,20 +19,20 @@ abstract class DiaryState with _$DiaryState {
|
||||
const factory DiaryState.loaded({
|
||||
required DiaryModel diary,
|
||||
String? diaryDate,
|
||||
required List<dynamic> autocompleteList,
|
||||
required List<int> recommendedChartValues,
|
||||
required List<int> consumedChartValues,
|
||||
required List<Portion> portions,
|
||||
required List<Photo> photos,
|
||||
required List<SelectionPopupModel> mealList,
|
||||
required List<SelectionPopupModel> portionList,
|
||||
required List<Product> autocompleteList,
|
||||
required Meal currentMeal,
|
||||
required SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
required TextEditingController commentController,
|
||||
required TextEditingController productNameController,
|
||||
required TextEditingController product_nameController,
|
||||
required TextEditingController productQuantityController,
|
||||
required TextEditingController caloriesController,
|
||||
required TextEditingController fatsController,
|
||||
|
||||
@@ -23,20 +23,20 @@ mixin _$DiaryState {
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -60,20 +60,20 @@ mixin _$DiaryState {
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -97,20 +97,20 @@ mixin _$DiaryState {
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -216,20 +216,20 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -256,20 +256,20 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -296,20 +296,20 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -417,20 +417,20 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -457,20 +457,20 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -497,20 +497,20 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -584,20 +584,20 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
|
||||
$Res call(
|
||||
{DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -628,20 +628,20 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
$Res call({
|
||||
Object? diary = null,
|
||||
Object? diaryDate = freezed,
|
||||
Object? autocompleteList = null,
|
||||
Object? recommendedChartValues = null,
|
||||
Object? consumedChartValues = null,
|
||||
Object? portions = null,
|
||||
Object? photos = null,
|
||||
Object? mealList = null,
|
||||
Object? portionList = null,
|
||||
Object? autocompleteList = null,
|
||||
Object? currentMeal = null,
|
||||
Object? portionController = null,
|
||||
Object? wakeupController = freezed,
|
||||
Object? retireController = freezed,
|
||||
Object? mealTimeController = freezed,
|
||||
Object? commentController = null,
|
||||
Object? productNameController = null,
|
||||
Object? product_nameController = null,
|
||||
Object? productQuantityController = null,
|
||||
Object? caloriesController = null,
|
||||
Object? fatsController = null,
|
||||
@@ -664,10 +664,6 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
? _value.diaryDate
|
||||
: diaryDate // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
autocompleteList: null == autocompleteList
|
||||
? _value._autocompleteList
|
||||
: autocompleteList // ignore: cast_nullable_to_non_nullable
|
||||
as List<dynamic>,
|
||||
recommendedChartValues: null == recommendedChartValues
|
||||
? _value._recommendedChartValues
|
||||
: recommendedChartValues // ignore: cast_nullable_to_non_nullable
|
||||
@@ -692,6 +688,10 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
? _value._portionList
|
||||
: portionList // ignore: cast_nullable_to_non_nullable
|
||||
as List<SelectionPopupModel>,
|
||||
autocompleteList: null == autocompleteList
|
||||
? _value._autocompleteList
|
||||
: autocompleteList // ignore: cast_nullable_to_non_nullable
|
||||
as List<Product>,
|
||||
currentMeal: null == currentMeal
|
||||
? _value.currentMeal
|
||||
: currentMeal // ignore: cast_nullable_to_non_nullable
|
||||
@@ -716,9 +716,9 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
? _value.commentController
|
||||
: commentController // ignore: cast_nullable_to_non_nullable
|
||||
as TextEditingController,
|
||||
productNameController: null == productNameController
|
||||
? _value.productNameController
|
||||
: productNameController // ignore: cast_nullable_to_non_nullable
|
||||
product_nameController: null == product_nameController
|
||||
? _value.product_nameController
|
||||
: product_nameController // ignore: cast_nullable_to_non_nullable
|
||||
as TextEditingController,
|
||||
productQuantityController: null == productQuantityController
|
||||
? _value.productQuantityController
|
||||
@@ -794,20 +794,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
const _$DiaryStateLoadedImpl(
|
||||
{required this.diary,
|
||||
this.diaryDate,
|
||||
required final List<dynamic> autocompleteList,
|
||||
required final List<int> recommendedChartValues,
|
||||
required final List<int> consumedChartValues,
|
||||
required final List<Portion> portions,
|
||||
required final List<Photo> photos,
|
||||
required final List<SelectionPopupModel> mealList,
|
||||
required final List<SelectionPopupModel> portionList,
|
||||
required final List<Product> autocompleteList,
|
||||
required this.currentMeal,
|
||||
required this.portionController,
|
||||
this.wakeupController,
|
||||
this.retireController,
|
||||
this.mealTimeController,
|
||||
required this.commentController,
|
||||
required this.productNameController,
|
||||
required this.product_nameController,
|
||||
required this.productQuantityController,
|
||||
required this.caloriesController,
|
||||
required this.fatsController,
|
||||
@@ -820,27 +820,18 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
required this.moodExpanded,
|
||||
required this.isLoading,
|
||||
required this.isAdded})
|
||||
: _autocompleteList = autocompleteList,
|
||||
_recommendedChartValues = recommendedChartValues,
|
||||
: _recommendedChartValues = recommendedChartValues,
|
||||
_consumedChartValues = consumedChartValues,
|
||||
_portions = portions,
|
||||
_photos = photos,
|
||||
_mealList = mealList,
|
||||
_portionList = portionList;
|
||||
_portionList = portionList,
|
||||
_autocompleteList = autocompleteList;
|
||||
|
||||
@override
|
||||
final DiaryModel diary;
|
||||
@override
|
||||
final String? diaryDate;
|
||||
final List<dynamic> _autocompleteList;
|
||||
@override
|
||||
List<dynamic> get autocompleteList {
|
||||
if (_autocompleteList is EqualUnmodifiableListView)
|
||||
return _autocompleteList;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_autocompleteList);
|
||||
}
|
||||
|
||||
final List<int> _recommendedChartValues;
|
||||
@override
|
||||
List<int> get recommendedChartValues {
|
||||
@@ -891,6 +882,15 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
return EqualUnmodifiableListView(_portionList);
|
||||
}
|
||||
|
||||
final List<Product> _autocompleteList;
|
||||
@override
|
||||
List<Product> get autocompleteList {
|
||||
if (_autocompleteList is EqualUnmodifiableListView)
|
||||
return _autocompleteList;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_autocompleteList);
|
||||
}
|
||||
|
||||
@override
|
||||
final Meal currentMeal;
|
||||
@override
|
||||
@@ -904,7 +904,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
@override
|
||||
final TextEditingController commentController;
|
||||
@override
|
||||
final TextEditingController productNameController;
|
||||
final TextEditingController product_nameController;
|
||||
@override
|
||||
final TextEditingController productQuantityController;
|
||||
@override
|
||||
@@ -932,7 +932,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DiaryState.loaded(diary: $diary, diaryDate: $diaryDate, autocompleteList: $autocompleteList, recommendedChartValues: $recommendedChartValues, consumedChartValues: $consumedChartValues, portions: $portions, photos: $photos, mealList: $mealList, portionList: $portionList, currentMeal: $currentMeal, portionController: $portionController, wakeupController: $wakeupController, retireController: $retireController, mealTimeController: $mealTimeController, commentController: $commentController, productNameController: $productNameController, productQuantityController: $productQuantityController, caloriesController: $caloriesController, fatsController: $fatsController, proteinsController: $proteinsController, carbsController: $carbsController, selectedMood: $selectedMood, selectedSatiety: $selectedSatiety, wakeupExpanded: $wakeupExpanded, moderationExpanded: $moderationExpanded, moodExpanded: $moodExpanded, isLoading: $isLoading, isAdded: $isAdded)';
|
||||
return 'DiaryState.loaded(diary: $diary, diaryDate: $diaryDate, recommendedChartValues: $recommendedChartValues, consumedChartValues: $consumedChartValues, portions: $portions, photos: $photos, mealList: $mealList, portionList: $portionList, autocompleteList: $autocompleteList, currentMeal: $currentMeal, portionController: $portionController, wakeupController: $wakeupController, retireController: $retireController, mealTimeController: $mealTimeController, commentController: $commentController, product_nameController: $product_nameController, productQuantityController: $productQuantityController, caloriesController: $caloriesController, fatsController: $fatsController, proteinsController: $proteinsController, carbsController: $carbsController, selectedMood: $selectedMood, selectedSatiety: $selectedSatiety, wakeupExpanded: $wakeupExpanded, moderationExpanded: $moderationExpanded, moodExpanded: $moodExpanded, isLoading: $isLoading, isAdded: $isAdded)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -943,8 +943,6 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
(identical(other.diary, diary) || other.diary == diary) &&
|
||||
(identical(other.diaryDate, diaryDate) ||
|
||||
other.diaryDate == diaryDate) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._autocompleteList, _autocompleteList) &&
|
||||
const DeepCollectionEquality().equals(
|
||||
other._recommendedChartValues, _recommendedChartValues) &&
|
||||
const DeepCollectionEquality()
|
||||
@@ -954,6 +952,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
const DeepCollectionEquality().equals(other._mealList, _mealList) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._portionList, _portionList) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._autocompleteList, _autocompleteList) &&
|
||||
(identical(other.currentMeal, currentMeal) ||
|
||||
other.currentMeal == currentMeal) &&
|
||||
(identical(other.portionController, portionController) ||
|
||||
@@ -966,8 +966,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
other.mealTimeController == mealTimeController) &&
|
||||
(identical(other.commentController, commentController) ||
|
||||
other.commentController == commentController) &&
|
||||
(identical(other.productNameController, productNameController) ||
|
||||
other.productNameController == productNameController) &&
|
||||
(identical(other.product_nameController, product_nameController) ||
|
||||
other.product_nameController == product_nameController) &&
|
||||
(identical(other.productQuantityController,
|
||||
productQuantityController) ||
|
||||
other.productQuantityController == productQuantityController) &&
|
||||
@@ -999,20 +999,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
runtimeType,
|
||||
diary,
|
||||
diaryDate,
|
||||
const DeepCollectionEquality().hash(_autocompleteList),
|
||||
const DeepCollectionEquality().hash(_recommendedChartValues),
|
||||
const DeepCollectionEquality().hash(_consumedChartValues),
|
||||
const DeepCollectionEquality().hash(_portions),
|
||||
const DeepCollectionEquality().hash(_photos),
|
||||
const DeepCollectionEquality().hash(_mealList),
|
||||
const DeepCollectionEquality().hash(_portionList),
|
||||
const DeepCollectionEquality().hash(_autocompleteList),
|
||||
currentMeal,
|
||||
portionController,
|
||||
wakeupController,
|
||||
retireController,
|
||||
mealTimeController,
|
||||
commentController,
|
||||
productNameController,
|
||||
product_nameController,
|
||||
productQuantityController,
|
||||
caloriesController,
|
||||
fatsController,
|
||||
@@ -1042,20 +1042,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -1074,20 +1074,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
return loaded(
|
||||
diary,
|
||||
diaryDate,
|
||||
autocompleteList,
|
||||
recommendedChartValues,
|
||||
consumedChartValues,
|
||||
portions,
|
||||
photos,
|
||||
mealList,
|
||||
portionList,
|
||||
autocompleteList,
|
||||
currentMeal,
|
||||
portionController,
|
||||
wakeupController,
|
||||
retireController,
|
||||
mealTimeController,
|
||||
commentController,
|
||||
productNameController,
|
||||
product_nameController,
|
||||
productQuantityController,
|
||||
caloriesController,
|
||||
fatsController,
|
||||
@@ -1110,20 +1110,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -1142,20 +1142,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
return loaded?.call(
|
||||
diary,
|
||||
diaryDate,
|
||||
autocompleteList,
|
||||
recommendedChartValues,
|
||||
consumedChartValues,
|
||||
portions,
|
||||
photos,
|
||||
mealList,
|
||||
portionList,
|
||||
autocompleteList,
|
||||
currentMeal,
|
||||
portionController,
|
||||
wakeupController,
|
||||
retireController,
|
||||
mealTimeController,
|
||||
commentController,
|
||||
productNameController,
|
||||
product_nameController,
|
||||
productQuantityController,
|
||||
caloriesController,
|
||||
fatsController,
|
||||
@@ -1178,20 +1178,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -1212,20 +1212,20 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
return loaded(
|
||||
diary,
|
||||
diaryDate,
|
||||
autocompleteList,
|
||||
recommendedChartValues,
|
||||
consumedChartValues,
|
||||
portions,
|
||||
photos,
|
||||
mealList,
|
||||
portionList,
|
||||
autocompleteList,
|
||||
currentMeal,
|
||||
portionController,
|
||||
wakeupController,
|
||||
retireController,
|
||||
mealTimeController,
|
||||
commentController,
|
||||
productNameController,
|
||||
product_nameController,
|
||||
productQuantityController,
|
||||
caloriesController,
|
||||
fatsController,
|
||||
@@ -1284,20 +1284,20 @@ abstract class DiaryStateLoaded implements DiaryState {
|
||||
const factory DiaryStateLoaded(
|
||||
{required final DiaryModel diary,
|
||||
final String? diaryDate,
|
||||
required final List<dynamic> autocompleteList,
|
||||
required final List<int> recommendedChartValues,
|
||||
required final List<int> consumedChartValues,
|
||||
required final List<Portion> portions,
|
||||
required final List<Photo> photos,
|
||||
required final List<SelectionPopupModel> mealList,
|
||||
required final List<SelectionPopupModel> portionList,
|
||||
required final List<Product> autocompleteList,
|
||||
required final Meal currentMeal,
|
||||
required final SelectionPopupModel portionController,
|
||||
final TimeOfDay? wakeupController,
|
||||
final TimeOfDay? retireController,
|
||||
final TimeOfDay? mealTimeController,
|
||||
required final TextEditingController commentController,
|
||||
required final TextEditingController productNameController,
|
||||
required final TextEditingController product_nameController,
|
||||
required final TextEditingController productQuantityController,
|
||||
required final TextEditingController caloriesController,
|
||||
required final TextEditingController fatsController,
|
||||
@@ -1313,20 +1313,20 @@ abstract class DiaryStateLoaded implements DiaryState {
|
||||
|
||||
DiaryModel get diary;
|
||||
String? get diaryDate;
|
||||
List<dynamic> get autocompleteList;
|
||||
List<int> get recommendedChartValues;
|
||||
List<int> get consumedChartValues;
|
||||
List<Portion> get portions;
|
||||
List<Photo> get photos;
|
||||
List<SelectionPopupModel> get mealList;
|
||||
List<SelectionPopupModel> get portionList;
|
||||
List<Product> get autocompleteList;
|
||||
Meal get currentMeal;
|
||||
SelectionPopupModel get portionController;
|
||||
TimeOfDay? get wakeupController;
|
||||
TimeOfDay? get retireController;
|
||||
TimeOfDay? get mealTimeController;
|
||||
TextEditingController get commentController;
|
||||
TextEditingController get productNameController;
|
||||
TextEditingController get product_nameController;
|
||||
TextEditingController get productQuantityController;
|
||||
TextEditingController get caloriesController;
|
||||
TextEditingController get fatsController;
|
||||
@@ -1415,20 +1415,20 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
required TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -1455,20 +1455,20 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TResult? Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
@@ -1495,20 +1495,20 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TResult Function(
|
||||
DiaryModel diary,
|
||||
String? diaryDate,
|
||||
List<dynamic> autocompleteList,
|
||||
List<int> recommendedChartValues,
|
||||
List<int> consumedChartValues,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos,
|
||||
List<SelectionPopupModel> mealList,
|
||||
List<SelectionPopupModel> portionList,
|
||||
List<Product> autocompleteList,
|
||||
Meal currentMeal,
|
||||
SelectionPopupModel portionController,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
TimeOfDay? mealTimeController,
|
||||
TextEditingController commentController,
|
||||
TextEditingController productNameController,
|
||||
TextEditingController product_nameController,
|
||||
TextEditingController productQuantityController,
|
||||
TextEditingController caloriesController,
|
||||
TextEditingController fatsController,
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/models/photo.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:eatvio_app/features/diary/models/product.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_bloc.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -247,7 +248,9 @@ class DiaryScreen extends StatelessWidget {
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости
|
||||
child: CircularProgressIndicator(
|
||||
color: appTheme
|
||||
.blueGray300), // Замените на свой прелоадер при необходимости
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -271,7 +274,8 @@ class DiaryScreen extends StatelessWidget {
|
||||
|
||||
_buildMeal(BuildContext context, DiaryStateLoaded state) {
|
||||
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
|
||||
List<String> _options = state.autocompleteList.map((dynamic item) => item as String).toList();
|
||||
List<String> _options =
|
||||
state.autocompleteList.map((Product item) => item.name).toList();
|
||||
FocusNode focusNodeName = FocusNode();
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h),
|
||||
@@ -315,7 +319,9 @@ 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,
|
||||
),
|
||||
),
|
||||
@@ -451,7 +457,9 @@ 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),
|
||||
/*...state.photos != null
|
||||
? state.photos!.isEmpty
|
||||
@@ -531,7 +539,7 @@ class DiaryScreen extends StatelessWidget {
|
||||
children: [
|
||||
CustomTextFormField(
|
||||
hintText: "Название",
|
||||
controller: state.productNameController,
|
||||
controller: state.product_nameController,
|
||||
),
|
||||
SizedBox(height: 10.v),
|
||||
CustomTextFormField(
|
||||
@@ -567,7 +575,7 @@ class DiaryScreen extends StatelessWidget {
|
||||
TextButton(
|
||||
onPressed: triggerModeration(
|
||||
context,
|
||||
state.productNameController.text,
|
||||
state.product_nameController.text,
|
||||
state.caloriesController.text,
|
||||
state.proteinsController.text,
|
||||
state.fatsController.text,
|
||||
@@ -608,7 +616,8 @@ 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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -618,8 +627,9 @@ class DiaryScreen extends StatelessWidget {
|
||||
};
|
||||
}
|
||||
|
||||
selectProduct(AutocompleteOnSelected<String> onSelected, String option, DiaryStateLoaded state) {
|
||||
state.productNameController.text = option;
|
||||
selectProduct(AutocompleteOnSelected<String> onSelected, String option,
|
||||
DiaryStateLoaded state) {
|
||||
state.product_nameController.text = option;
|
||||
return () {
|
||||
onSelected(option);
|
||||
};
|
||||
@@ -660,7 +670,8 @@ class DiaryScreen extends StatelessWidget {
|
||||
return CarouselSlider(
|
||||
options: CarouselOptions(height: 340.0),
|
||||
items: state.currentMeal.photos.map<Widget>((photo) {
|
||||
return _buildPhoto(context, photo); // Assuming photos are stored as strings
|
||||
return _buildPhoto(
|
||||
context, photo); // Assuming photos are stored as strings
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
@@ -686,7 +697,9 @@ class DiaryScreen extends StatelessWidget {
|
||||
top: 5.v,
|
||||
),
|
||||
child: Text(
|
||||
portion.productName.length > 8 ? portion.productName.substring(0, 8) : portion.productName,
|
||||
portion.product_name.length > 8
|
||||
? portion.product_name.substring(0, 8)
|
||||
: portion.product_name,
|
||||
style: CustomTextStyles.titleMedium16,
|
||||
),
|
||||
),
|
||||
@@ -758,12 +771,15 @@ 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> recommendedValues = state
|
||||
.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы
|
||||
final List<int> consumedValues = state.consumedChartValues; //
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h),
|
||||
@@ -827,7 +843,10 @@ class DiaryScreen extends StatelessWidget {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[0] / recommendedValues[0] * 100,
|
||||
color: checkConsumedValues([recommendedValues[0]], [consumedValues[1]]) ? Colors.red : Colors.blue,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[0]], [consumedValues[1]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -836,7 +855,10 @@ class DiaryScreen extends StatelessWidget {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[1] / recommendedValues[1] * 100,
|
||||
color: checkConsumedValues([recommendedValues[1]], [consumedValues[1]]) ? Colors.red : Colors.blue,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[1]], [consumedValues[1]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -845,7 +867,10 @@ class DiaryScreen extends StatelessWidget {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[2] / recommendedValues[2] * 100,
|
||||
color: checkConsumedValues([recommendedValues[2]], [consumedValues[2]]) ? Colors.red : Colors.blue,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[2]], [consumedValues[2]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -854,7 +879,10 @@ class DiaryScreen extends StatelessWidget {
|
||||
barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[3] / recommendedValues[3] * 100,
|
||||
color: checkConsumedValues([recommendedValues[3]], [consumedValues[3]]) ? Colors.red : Colors.blue,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[3]], [consumedValues[3]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1045,7 +1073,9 @@ 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),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1059,7 +1089,8 @@ 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,
|
||||
),
|
||||
@@ -1070,7 +1101,8 @@ 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,
|
||||
),
|
||||
@@ -1117,7 +1149,8 @@ class DiaryScreen extends StatelessWidget {
|
||||
};
|
||||
}
|
||||
|
||||
Function() sendFinishDayData(BuildContext dialogContext, BuildContext context) {
|
||||
Function() sendFinishDayData(
|
||||
BuildContext dialogContext, BuildContext context) {
|
||||
return () {
|
||||
closeDialog(dialogContext);
|
||||
context.read<DiaryBloc>().add(FinishDay());
|
||||
@@ -1160,7 +1193,9 @@ 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),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1220,7 +1255,8 @@ 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(),
|
||||
@@ -1230,7 +1266,8 @@ class DiaryScreen extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
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(),
|
||||
@@ -1240,7 +1277,8 @@ class DiaryScreen extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
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(),
|
||||
@@ -1251,7 +1289,8 @@ 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]) {
|
||||
// Если хотя бы одно потребленное значение превышает рекомендованное
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:eatvio_app/features/diary/models/product.dart';
|
||||
import 'package:eatvio_app/features/diary/services/diary_service.dart';
|
||||
|
||||
@@ -83,7 +84,7 @@ class DiaryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addPortion(
|
||||
Future<Map<String, Portion>> addPortion(
|
||||
int diaryID,
|
||||
int mealID,
|
||||
String name,
|
||||
@@ -91,7 +92,8 @@ class DiaryRepository {
|
||||
int quantity,
|
||||
) async {
|
||||
try {
|
||||
await diaryService.sendPortionData(
|
||||
print(name);
|
||||
return await diaryService.sendPortionData(
|
||||
diaryID,
|
||||
mealID,
|
||||
name,
|
||||
@@ -109,6 +111,9 @@ class DiaryRepository {
|
||||
int portionID,
|
||||
) async {
|
||||
try {
|
||||
print(diaryID);
|
||||
print(mealID);
|
||||
print(portionID);
|
||||
await diaryService.sendRemovePortionData(
|
||||
diaryID,
|
||||
mealID,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:eatvio_app/features/diary/models/product.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
@@ -49,7 +50,7 @@ abstract class DiaryService {
|
||||
);
|
||||
|
||||
@POST('/diary/{diary_id}/meal/{meal_id}/portions/create')
|
||||
Future<Map<String, int>> sendPortionData(
|
||||
Future<Map<String, Portion>> sendPortionData(
|
||||
@Path() int diary_id,
|
||||
@Path() int meal_id,
|
||||
@Query('product_name') String product_name,
|
||||
@@ -57,8 +58,8 @@ abstract class DiaryService {
|
||||
@Query('quantity') int quantity,
|
||||
);
|
||||
|
||||
@POST('/diary/{diary_id}/meal/{meal_id}/portions/{portion_id}/delete')
|
||||
Future<Map<String, int>> sendRemovePortionData(
|
||||
@DELETE('/diary/{diary_id}/meal/{meal_id}/portions/{portion_id}/delete')
|
||||
Future<void> sendRemovePortionData(
|
||||
@Path() int diary_id,
|
||||
@Path() int meal_id,
|
||||
@Path() int portion_id,
|
||||
|
||||
@@ -254,7 +254,7 @@ class _DiaryService implements DiaryService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, int>> sendPortionData(
|
||||
Future<Map<String, Portion>> sendPortionData(
|
||||
int diary_id,
|
||||
int meal_id,
|
||||
String product_name,
|
||||
@@ -269,8 +269,8 @@ class _DiaryService implements DiaryService {
|
||||
};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<Map<String, int>>(Options(
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(
|
||||
_setStreamType<Map<String, Portion>>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
@@ -286,12 +286,13 @@ class _DiaryService implements DiaryService {
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = _result.data!.cast<String, int>();
|
||||
var _value = _result.data!.map((k, dynamic v) =>
|
||||
MapEntry(k, Portion.fromJson(v as Map<String, dynamic>)));
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, int>> sendRemovePortionData(
|
||||
Future<void> sendRemovePortionData(
|
||||
int diary_id,
|
||||
int meal_id,
|
||||
int portion_id,
|
||||
@@ -300,25 +301,22 @@ class _DiaryService implements DiaryService {
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<Map<String, int>>(Options(
|
||||
method: 'POST',
|
||||
await _dio.fetch<void>(_setStreamType<void>(Options(
|
||||
method: 'DELETE',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/diary/${diary_id}/meal/${meal_id}/portions/${portion_id}/delete',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = _result.data!.cast<String, int>();
|
||||
return _value;
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/diary/${diary_id}/meal/${meal_id}/portions/${portion_id}/delete',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
|
||||
Reference in New Issue
Block a user