feat(diary): Checkboxes for product when diet is chosen

This commit is contained in:
2024-08-16 16:26:22 +03:00
parent 684b2eec9d
commit 9497789eb5
11 changed files with 369 additions and 63 deletions

View File

@@ -54,10 +54,8 @@ class DiaryRecommendationsScreen extends StatelessWidget {
);
}
Widget _buildDiaryRecommendations(
BuildContext context, DiaryStateLoaded state) {
final Portion product =
new Portion(id: 1, product_name: "", quantity: 1, portion: "");
Widget _buildDiaryRecommendations(BuildContext context, DiaryStateLoaded state) {
final Portion product = new Portion(id: 1, product_name: "", quantity: 1, portion: "", from_diet: true);
return Stack(
alignment: Alignment.bottomCenter,
children: [
@@ -88,13 +86,9 @@ class DiaryRecommendationsScreen extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Название продукта: ${product.product_name}',
style: TextStyle(fontSize: 24)),
Text('Название продукта: ${product.product_name}', style: TextStyle(fontSize: 24)),
SizedBox(height: 16),
Text(
'Количество: ${product.quantity} ${product.portion}',
style: TextStyle(fontSize: 18)),
Text('Количество: ${product.quantity} ${product.portion}', style: TextStyle(fontSize: 18)),
// Добавьте другие детали о продукте по необходимости
],
),

View File

@@ -154,8 +154,7 @@ class DiaryScreen extends StatelessWidget {
trackOpacity: 0.1,
gap: "8%",
radius: "110%",
innerRadius:
'20%', // Измените значение по вашему усмотрению
innerRadius: '20%', // Измените значение по вашему усмотрению
)
],
),
@@ -338,9 +337,7 @@ class DiaryScreen extends StatelessWidget {
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Center(
child: CircularProgressIndicator(
color: appTheme
.blueGray300), // Замените на свой прелоадер при необходимости
child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости
),
),
],
@@ -366,8 +363,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(
padding: EdgeInsets.symmetric(
@@ -402,9 +398,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,
),
),
@@ -540,9 +534,8 @@ class DiaryScreen extends StatelessWidget {
SizedBox(height: 24.v),
_buildAddProduct(context, state),
SizedBox(height: 24.v),
...state.portions
.map((portion) => _buildProduct(context, portion))
.toList(),
if (!state.diary.state.has_chosen_diet) ...state.portions.map((portion) => _buildProduct(context, portion)).toList(),
if (state.diary.state.has_chosen_diet) ...state.portions.map((portion) => _buildProductDiet(context, portion)).toList(),
SizedBox(height: 24.v),
_buildCarousel(context, state),
SizedBox(height: 24.v),
@@ -691,8 +684,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
};
}
@@ -702,8 +694,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);
@@ -771,9 +762,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,
),
),
@@ -803,6 +792,63 @@ class DiaryScreen extends StatelessWidget {
);
}
_buildProductDiet(BuildContext context, Portion portion) {
return Container(
margin: EdgeInsets.symmetric(
horizontal: 10.h,
vertical: 4.h,
),
padding: EdgeInsets.symmetric(
horizontal: 8.h,
vertical: 6.v,
),
decoration: AppDecoration.fillGray.copyWith(
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: !portion.from_diet,
onChanged: (bool? value) {},
),
Padding(
padding: EdgeInsets.only(
left: 7.h,
top: 5.v,
),
child: Text(
portion.product_name.length > 8 ? portion.product_name.substring(0, 8) : portion.product_name,
style: CustomTextStyles.titleMedium16,
),
),
Padding(
padding: EdgeInsets.only(
left: 20.h,
top: 3.v,
bottom: 3.v,
),
child: Text(
portion.quantity.toString() + ' ' + portion.portion.toString().tr,
),
),
Spacer(),
GestureDetector(
onTap: () => removePortion(context, portion), // Обернуть в лямбду
child: Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(
Icons.close,
color: appTheme.blueGray300,
),
),
),
],
),
);
}
_buildPhoto(BuildContext context, Photo photo, DiaryStateLoaded state) {
return Stack(
children: [
@@ -861,9 +907,7 @@ 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));
};
}
@@ -923,9 +967,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),
],
),
),
@@ -939,8 +981,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,
),
@@ -951,8 +992,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,
),
@@ -999,8 +1039,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());
@@ -1034,9 +1073,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),
],
),
),
@@ -1096,8 +1133,7 @@ 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,
@@ -1107,8 +1143,7 @@ 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,
@@ -1118,8 +1153,7 @@ 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(),
@@ -1130,8 +1164,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]) {
// Если хотя бы одно потребленное значение превышает рекомендованное