feat(diary): Chart refactor, photo add and delete refactor

This commit is contained in:
2024-08-09 17:29:41 +03:00
parent 16d0863958
commit e72ecb5e28

View File

@@ -150,6 +150,12 @@ class DiaryScreen extends StatelessWidget {
xValueMapper: (NutritionData data, _) => data.category,
yValueMapper: (NutritionData data, _) => data.nutrition,
pointColorMapper: (NutritionData data, _) => data.color,
trackColor: Color.fromRGBO(59, 130, 246, 1),
trackOpacity: 0.1,
gap: "8%",
radius: "110%",
innerRadius:
'20%', // Измените значение по вашему усмотрению
)
],
),
@@ -332,7 +338,9 @@ class DiaryScreen extends StatelessWidget {
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Center(
child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости
child: CircularProgressIndicator(
color: appTheme
.blueGray300), // Замените на свой прелоадер при необходимости
),
),
],
@@ -358,7 +366,8 @@ 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(
@@ -393,7 +402,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,
),
),
@@ -529,7 +540,9 @@ class DiaryScreen extends StatelessWidget {
SizedBox(height: 24.v),
_buildAddProduct(context, state),
SizedBox(height: 24.v),
...state.portions.map((portion) => _buildProduct(context, portion)).toList(),
...state.portions
.map((portion) => _buildProduct(context, portion))
.toList(),
SizedBox(height: 24.v),
_buildCarousel(context, state),
SizedBox(height: 24.v),
@@ -678,7 +691,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
};
}
@@ -688,7 +702,8 @@ 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);
@@ -730,7 +745,7 @@ class DiaryScreen extends StatelessWidget {
return CarouselSlider(
options: CarouselOptions(height: 200.0),
items: state.currentMeal.photos.map<Widget>((photo) {
return _buildPhoto(context, photo);
return _buildPhoto(context, photo, state);
}).toList(),
);
}
@@ -756,7 +771,9 @@ 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,
),
),
@@ -786,7 +803,7 @@ class DiaryScreen extends StatelessWidget {
);
}
_buildPhoto(BuildContext context, Photo photo) {
_buildPhoto(BuildContext context, Photo photo, DiaryStateLoaded state) {
return Stack(
children: [
Container(
@@ -821,14 +838,12 @@ class DiaryScreen extends StatelessWidget {
IconButton(
icon: Icon(Icons.photo_outlined),
color: Colors.white,
onPressed: () {
// Ваш код для кнопки фотографии
},
onPressed: addImage(context, state.isLoading),
),
IconButton(
icon: Icon(Icons.delete_outlined),
color: Colors.white,
onPressed: () => removePhoto(context, photo),
onPressed: removePhoto(context, photo),
),
],
),
@@ -846,7 +861,9 @@ 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));
};
}
@@ -906,7 +923,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),
],
),
),
@@ -920,7 +939,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,
),
@@ -931,7 +951,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,
),
@@ -978,7 +999,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());
@@ -1012,7 +1034,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),
],
),
),
@@ -1072,7 +1096,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,
@@ -1082,7 +1107,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,
@@ -1092,7 +1118,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(),
@@ -1103,7 +1130,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]) {
// Если хотя бы одно потребленное значение превышает рекомендованное