forked from eatvio/eatvio_app
feat(diary): Nutrition chart with fl_charts
This commit is contained in:
@@ -612,8 +612,9 @@ class DiaryEditScreen extends StatelessWidget {
|
|||||||
top: 5.v,
|
top: 5.v,
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
portion['product_name']
|
portion['product_name'].length > 8
|
||||||
.substring(0, 8), // Обрезаем название до 8 символов
|
? portion['product_name'].substring(0, 8)
|
||||||
|
: portion['product_name'],
|
||||||
style: CustomTextStyles.titleMedium16,
|
style: CustomTextStyles.titleMedium16,
|
||||||
)),
|
)),
|
||||||
Padding(
|
Padding(
|
||||||
@@ -650,6 +651,13 @@ class DiaryEditScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildNutritionChart(BuildContext context) {
|
_buildNutritionChart(BuildContext context) {
|
||||||
|
final List<double> recommendedValues = [
|
||||||
|
2000,
|
||||||
|
70,
|
||||||
|
50,
|
||||||
|
300
|
||||||
|
]; // Рекомендуемые значения: калории, жиры, белки, углеводы
|
||||||
|
final List<double> consumedValues = [1800, 60, 40, 250]; //
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.symmetric(horizontal: 16.h),
|
margin: EdgeInsets.symmetric(horizontal: 16.h),
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
@@ -690,112 +698,50 @@ class DiaryEditScreen extends StatelessWidget {
|
|||||||
left: 30.h,
|
left: 30.h,
|
||||||
right: 12.h,
|
right: 12.h,
|
||||||
),
|
),
|
||||||
child: Row(
|
child: AspectRatio(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
aspectRatio: 1.5,
|
||||||
children: [
|
child: BarChart(
|
||||||
Container(
|
BarChartData(
|
||||||
margin: EdgeInsets.only(top: 7.v),
|
alignment: BarChartAlignment.spaceAround,
|
||||||
decoration: AppDecoration.outlinePrimary.copyWith(
|
barTouchData: BarTouchData(enabled: false),
|
||||||
borderRadius: BorderRadiusStyle.roundedBorder1,
|
titlesData: FlTitlesData(
|
||||||
),
|
show: true,
|
||||||
child: Column(
|
bottomTitles: AxisTitles(
|
||||||
mainAxisSize: MainAxisSize.min,
|
sideTitles: SideTitles(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
showTitles: true,
|
||||||
children: [
|
getTitlesWidget: (value, meta) => newMethod(value),
|
||||||
SizedBox(height: 101.v),
|
|
||||||
Container(
|
|
||||||
height: 47.v,
|
|
||||||
width: 12.h,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: theme.colorScheme.errorContainer,
|
|
||||||
borderRadius: BorderRadius.vertical(
|
|
||||||
bottom: Radius.circular(1.h),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Spacer(
|
|
||||||
flex: 33,
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(top: 7.v),
|
|
||||||
decoration: AppDecoration.outlinePrimary.copyWith(
|
|
||||||
borderRadius: BorderRadiusStyle.roundedBorder1,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
SizedBox(height: 66.v),
|
|
||||||
Container(
|
|
||||||
height: 82.v,
|
|
||||||
width: 12.h,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: appTheme.lightGreenA700,
|
|
||||||
borderRadius: BorderRadius.vertical(
|
|
||||||
bottom: Radius.circular(1.h),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Spacer(
|
|
||||||
flex: 33,
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(top: 7.v),
|
|
||||||
decoration: AppDecoration.outlinePrimary.copyWith(
|
|
||||||
borderRadius: BorderRadiusStyle.roundedBorder1,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
SizedBox(height: 14.v),
|
|
||||||
Container(
|
|
||||||
height: 134.v,
|
|
||||||
width: 12.h,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red,
|
|
||||||
borderRadius: BorderRadius.vertical(
|
|
||||||
bottom: Radius.circular(1.h),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Spacer(
|
|
||||||
flex: 33,
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
margin: EdgeInsets.only(top: 7.v),
|
|
||||||
decoration: AppDecoration.outlinePrimary.copyWith(
|
|
||||||
borderRadius: BorderRadiusStyle.roundedBorder1,
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
height: 148.v,
|
|
||||||
width: 12.h,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red,
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
1.h,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
borderData: FlBorderData(show: false),
|
||||||
|
barGroups: [
|
||||||
|
BarChartGroupData(x: 0, barRods: [
|
||||||
|
BarChartRodData(
|
||||||
|
toY: consumedValues[0] / recommendedValues[0] * 100,
|
||||||
|
color: Colors.blue,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
BarChartGroupData(x: 1, barRods: [
|
||||||
|
BarChartRodData(
|
||||||
|
toY: consumedValues[1] / recommendedValues[1] * 100,
|
||||||
|
color: Colors.red,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
BarChartGroupData(x: 2, barRods: [
|
||||||
|
BarChartRodData(
|
||||||
|
toY: consumedValues[2] / recommendedValues[2] * 100,
|
||||||
|
color: Colors.green,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
BarChartGroupData(x: 3, barRods: [
|
||||||
|
BarChartRodData(
|
||||||
|
toY: consumedValues[3] / recommendedValues[3] * 100,
|
||||||
|
color: Colors.orange,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
),
|
||||||
padding: EdgeInsets.only(
|
|
||||||
left: 6.h,
|
|
||||||
bottom: 128.v,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
"*",
|
|
||||||
style: theme.textTheme.titleLarge,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -888,6 +834,21 @@ class DiaryEditScreen extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget newMethod(double value) {
|
||||||
|
switch (value.toInt()) {
|
||||||
|
case 0:
|
||||||
|
return Text('Calories');
|
||||||
|
case 1:
|
||||||
|
return Text('Fat');
|
||||||
|
case 2:
|
||||||
|
return Text('Protein');
|
||||||
|
case 3:
|
||||||
|
return Text('Carbs');
|
||||||
|
default:
|
||||||
|
return Text('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildBars(BuildContext context, DiaryEditLoadedState state) {}
|
buildBars(BuildContext context, DiaryEditLoadedState state) {}
|
||||||
|
|
||||||
/// Section Widget
|
/// Section Widget
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import 'package:eatvio_app/core/app_export.dart';
|
||||||
|
import 'package:eatvio_app/widgets/base_button.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class NextStepButton extends BaseButton {
|
||||||
|
NextStepButton({
|
||||||
|
Key? key,
|
||||||
|
this.decoration,
|
||||||
|
this.leftIcon,
|
||||||
|
this.rightIcon,
|
||||||
|
this.label,
|
||||||
|
VoidCallback? onPressed,
|
||||||
|
ButtonStyle? buttonStyle,
|
||||||
|
TextStyle? buttonTextStyle,
|
||||||
|
bool? isDisabled,
|
||||||
|
Alignment? alignment,
|
||||||
|
double? height,
|
||||||
|
double? width,
|
||||||
|
EdgeInsets? margin,
|
||||||
|
required String text,
|
||||||
|
}) : super(
|
||||||
|
text: text,
|
||||||
|
onPressed: onPressed,
|
||||||
|
buttonStyle: buttonStyle,
|
||||||
|
isDisabled: isDisabled,
|
||||||
|
buttonTextStyle: buttonTextStyle,
|
||||||
|
height: height,
|
||||||
|
alignment: alignment,
|
||||||
|
width: width,
|
||||||
|
margin: margin,
|
||||||
|
);
|
||||||
|
|
||||||
|
final BoxDecoration? decoration;
|
||||||
|
final Widget? leftIcon;
|
||||||
|
final Widget? rightIcon;
|
||||||
|
final Widget? label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return (alignment != null)
|
||||||
|
? Align(
|
||||||
|
alignment: alignment!,
|
||||||
|
child: Container(
|
||||||
|
height: this.height ?? 30.v,
|
||||||
|
width: this.width ?? double.maxFinite,
|
||||||
|
margin: margin,
|
||||||
|
decoration: decoration,
|
||||||
|
child: OutlinedButton(
|
||||||
|
style: buttonStyle,
|
||||||
|
onPressed: isDisabled ?? false ? null : onPressed ?? () {},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
leftIcon ?? const SizedBox.shrink(),
|
||||||
|
Text(
|
||||||
|
text,
|
||||||
|
style: buttonTextStyle ?? theme.textTheme.titleSmall,
|
||||||
|
),
|
||||||
|
rightIcon ?? const SizedBox.shrink(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(
|
||||||
|
height: this.height ?? 30.v,
|
||||||
|
width: this.width ?? double.maxFinite,
|
||||||
|
margin: margin,
|
||||||
|
decoration: decoration,
|
||||||
|
child: OutlinedButton(
|
||||||
|
style: buttonStyle,
|
||||||
|
onPressed: isDisabled ?? false ? null : onPressed ?? () {},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
leftIcon ?? const SizedBox.shrink(),
|
||||||
|
Text(
|
||||||
|
text,
|
||||||
|
style: buttonTextStyle ?? theme.textTheme.titleSmall,
|
||||||
|
),
|
||||||
|
rightIcon ?? const SizedBox.shrink(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user