forked from eatvio/eatvio_app
fix(diary): Remove portion API call fixed
This commit is contained in:
@@ -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]) {
|
||||
// Если хотя бы одно потребленное значение превышает рекомендованное
|
||||
|
||||
Reference in New Issue
Block a user