feat(diary): Nutrition chart looks like half-donut

This commit is contained in:
2024-07-31 12:21:17 +03:00
parent 56e5cdbe16
commit a2360a1c19
5 changed files with 181 additions and 80 deletions

View File

@@ -111,35 +111,80 @@ class DiaryScreen extends StatelessWidget {
_buildNutritionChart(BuildContext context, DiaryStateLoaded state) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h),
padding: EdgeInsets.symmetric(
horizontal: 24.h,
vertical: 12.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: SfCircularChart(
title: ChartTitle(text: 'График КБЖУ'),
legend: Legend(isVisible: true),
series: <CircularSeries>[
RadialBarSeries<NutritionData, String>(
dataSource: state.chartData,
xValueMapper: (NutritionData data, _) => data.category,
yValueMapper: (NutritionData data, _) => data.nutrition,
pointColorMapper: (NutritionData data, _) => data.color,
)
],
));
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h),
padding: EdgeInsets.symmetric(
horizontal: 24.h,
vertical: 12.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(
children: [
Text(
"График КБЖУ",
style: theme.textTheme.titleMedium,
textAlign: TextAlign.center,
),
Transform.rotate(
angle: -1.5708,
child: ClipRect(
child: Align(
alignment: Alignment.centerRight,
widthFactor: 0.5,
child: SfCircularChart(
legend: Legend(isVisible: false),
series: <CircularSeries>[
RadialBarSeries<NutritionData, String>(
dataSource: state.chartData,
xValueMapper: (NutritionData data, _) => data.category,
yValueMapper: (NutritionData data, _) => data.nutrition,
pointColorMapper: (NutritionData data, _) => data.color,
)
],
),
),
)),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Калории'),
Text('Белки'),
Text('Жиры'),
Text('Углеводы'),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'${state.chartData![0].nutrition.toStringAsFixed(1)}'), // Калории
Text(
'${state.chartData![1].nutrition.toStringAsFixed(1)}'), // Белки
Text(
'${state.chartData![2].nutrition.toStringAsFixed(1)}'), // Жиры
Text(
'${state.chartData![3].nutrition.toStringAsFixed(1)}'), // Углеводы
],
),
],
),
],
),
);
}
_buildEndDay(BuildContext context) {
@@ -278,7 +323,9 @@ class DiaryScreen extends StatelessWidget {
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Center(
child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости
child: CircularProgressIndicator(
color: appTheme
.blueGray300), // Замените на свой прелоадер при необходимости
),
),
],
@@ -302,7 +349,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(
margin: EdgeInsets.symmetric(horizontal: 16.h),
@@ -346,7 +394,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,
),
),
@@ -482,7 +532,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),
_buildCarousel(context, state),
SizedBox(height: 20.v),
@@ -631,7 +683,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
};
}
@@ -641,7 +694,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);
@@ -709,7 +763,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,
),
),
@@ -781,7 +837,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));
};
}
@@ -859,7 +917,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),
],
),
),
@@ -873,7 +933,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,
),
@@ -884,7 +945,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,
),
@@ -931,7 +993,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());
@@ -974,7 +1037,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),
],
),
),
@@ -1034,7 +1099,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,
@@ -1044,7 +1110,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,
@@ -1054,7 +1121,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(),
@@ -1065,7 +1133,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]) {
// Если хотя бы одно потребленное значение превышает рекомендованное