refactor: profile model

This commit is contained in:
mso7nueh
2024-09-09 18:18:35 +03:00
parent 3ccf5b6d92
commit 8ea819c5bc
77 changed files with 2735 additions and 2950 deletions

View File

@@ -1,374 +1,374 @@
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class CircumferenceChartWidget extends StatefulWidget {
final List<Circumference> chartData;
final ProfileCubit profileCubit;
const CircumferenceChartWidget({
super.key,
required this.chartData,
required this.profileCubit,
});
@override
State<CircumferenceChartWidget> createState() => _CircumferenceChartWidgetState();
}
class _CircumferenceChartWidgetState extends State<CircumferenceChartWidget> {
late FixedExtentScrollController chestController;
late FixedExtentScrollController waistController;
late FixedExtentScrollController hipController;
late int chest;
late int waist;
late int hip;
@override
Widget build(BuildContext context) {
return Column(
children: [
if (widget.chartData.isNotEmpty)
Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'${widget.chartData.last.chestCircumference}',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.w500,
),
),
if (widget.chartData.length == 1)
Container(
margin: EdgeInsets.symmetric(horizontal: 12),
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
if (widget.chartData.length > 1)
widget.chartData.last.chestCircumference > widget.chartData[widget.chartData.length - 2].chestCircumference
? Icon(
Icons.arrow_drop_up,
size: 40,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 40,
color: Colors.grey,
),
Text(
'${widget.chartData.last.waistCircumference}',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.w500,
),
),
if (widget.chartData.length == 1)
Container(
margin: EdgeInsets.symmetric(horizontal: 12),
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
if (widget.chartData.length > 1)
widget.chartData.last.waistCircumference > widget.chartData[widget.chartData.length - 2].waistCircumference
? Icon(
Icons.arrow_drop_up,
size: 40,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 40,
color: Colors.grey,
),
Text(
'${widget.chartData.last.hipCircumference}',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.w500,
),
),
if (widget.chartData.length == 1)
Container(
margin: EdgeInsets.symmetric(horizontal: 12),
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
if (widget.chartData.length > 1)
widget.chartData.last.hipCircumference > widget.chartData[widget.chartData.length - 2].hipCircumference
? Icon(
Icons.arrow_drop_up,
size: 40,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 40,
color: Colors.grey,
),
],
),
),
Stack(
alignment: Alignment.bottomRight,
children: [
SfCartesianChart(
margin: EdgeInsets.symmetric(horizontal: 8),
enableAxisAnimation: true,
plotAreaBorderWidth: 0,
trackballBehavior: TrackballBehavior(
enable: true,
activationMode: ActivationMode.singleTap,
tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
tooltipSettings: InteractiveTooltip(),
lineType: TrackballLineType.vertical,
),
primaryXAxis: DateTimeCategoryAxis(
tickPosition: TickPosition.inside,
majorTickLines: MajorTickLines(
size: 0,
),
edgeLabelPlacement: EdgeLabelPlacement.shift,
dateFormat: DateFormat.MMMd('ru'),
labelStyle: TextStyle(
color: Colors.grey,
),
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
axisLine: AxisLine(
color: Colors.grey.withOpacity(0.3),
width: 0.4,
),
),
primaryYAxis: NumericAxis(
isVisible: false,
labelFormat: '{value} см',
axisLine: AxisLine(
width: 1,
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
FloatingActionButton.small(
heroTag: 'addCircumference',
onPressed: () {
if (widget.chartData.isNotEmpty) {
chest = widget.chartData.last.chestCircumference;
waist = widget.chartData.last.waistCircumference;
hip = widget.chartData.last.hipCircumference;
chestController = FixedExtentScrollController(initialItem: chest - 20);
waistController = FixedExtentScrollController(initialItem: waist - 20);
hipController = FixedExtentScrollController(initialItem: hip - 20);
} else {
chestController = FixedExtentScrollController();
waistController = FixedExtentScrollController();
hipController = FixedExtentScrollController();
}
showModalBottomSheet(
useRootNavigator: true,
context: context,
builder: (context) {
return Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
scrollController: chestController,
itemExtent: 24,
onSelectedItemChanged: (int value) {
chest = value;
},
children: [
for (int i = 20; i < 200; i++) Text('$i'),
],
),
),
Expanded(
child: CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
scrollController: waistController,
itemExtent: 24,
onSelectedItemChanged: (int value) {
waist = value;
},
children: [
for (int i = 20; i < 200; i++) Text('$i'),
],
),
),
Expanded(
child: CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
scrollController: hipController,
itemExtent: 24,
onSelectedItemChanged: (int value) {
hip = value;
},
children: [
for (int i = 20; i < 200; i++) Text('$i'),
],
),
),
],
),
),
InkWell(
onTap: () {
widget.profileCubit.addCircumference(
chestCircumference: chest,
waistCircumference: waist,
hipCircumference: hip,
);
Navigator.of(context).pop();
},
borderRadius: BorderRadius.circular(16),
child: Ink(
width: MediaQuery.of(context).size.width - 32,
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: BorderRadius.circular(16),
),
child: Center(
child: Text(
'Сохранить',
style: TextStyle(
color: Colors.white,
),
),
),
),
),
],
);
},
);
},
backgroundColor: Colors.red,
shape: CircleBorder(),
child: Icon(
Icons.add,
color: Colors.white,
),
),
],
),
],
);
}
List<CartesianSeries<Circumference, DateTime>> _getSplineSeries() {
final Color seriesColor1 = Colors.red;
final Color seriesColor2 = appTheme.blueA400;
final Color seriesColor3 = Colors.green;
return <CartesianSeries<Circumference, DateTime>>[
SplineAreaSeries<Circumference, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: seriesColor1,
height: 8,
width: 8,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: widget.chartData,
borderColor: seriesColor1,
gradient: LinearGradient(
colors: [
seriesColor1.withOpacity(0.14),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment(0, 0.6),
),
name: 'Грудь',
xValueMapper: (Circumference value, int index) => value.createdAt,
yValueMapper: (Circumference value, int index) => value.chestCircumference,
),
SplineAreaSeries<Circumference, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: seriesColor2,
height: 8,
width: 8,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: widget.chartData,
borderColor: seriesColor2,
gradient: LinearGradient(
colors: [
seriesColor2.withOpacity(0.14),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment(0, 0.6),
),
name: 'Талия',
xValueMapper: (Circumference value, int index) => value.createdAt,
yValueMapper: (Circumference value, int index) => value.waistCircumference,
),
SplineAreaSeries<Circumference, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: seriesColor3,
height: 8,
width: 8,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: widget.chartData,
borderColor: seriesColor3,
gradient: LinearGradient(
colors: [
seriesColor3.withOpacity(0.14),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment(0, 0.6),
),
name: 'Бёдра',
xValueMapper: (Circumference value, int index) => value.createdAt,
yValueMapper: (Circumference value, int index) => value.hipCircumference,
),
];
}
}
// import 'package:eatvio_app/core/app_export.dart';
// import 'package:eatvio_app/features/profile/models/profile_model.dart';
// import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
// import 'package:flutter/cupertino.dart';
// import 'package:flutter/material.dart';
// import 'package:intl/intl.dart';
// import 'package:syncfusion_flutter_charts/charts.dart';
//
// class CircumferenceChartWidget extends StatefulWidget {
// final List<Circumference> chartData;
// final ProfileCubit profileCubit;
//
// const CircumferenceChartWidget({
// super.key,
// required this.chartData,
// required this.profileCubit,
// });
//
// @override
// State<CircumferenceChartWidget> createState() => _CircumferenceChartWidgetState();
// }
//
// class _CircumferenceChartWidgetState extends State<CircumferenceChartWidget> {
// late FixedExtentScrollController chestController;
// late FixedExtentScrollController waistController;
// late FixedExtentScrollController hipController;
// late int chest;
// late int waist;
// late int hip;
//
// @override
// Widget build(BuildContext context) {
// return Column(
// children: [
// if (widget.chartData.isNotEmpty)
// Padding(
// padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
// child: Row(
// children: [
// Text(
// '${widget.chartData.last.chestCircumference}',
// style: TextStyle(
// color: Colors.black,
// fontSize: 40,
// fontWeight: FontWeight.w500,
// ),
// ),
// if (widget.chartData.length == 1)
// Container(
// margin: EdgeInsets.symmetric(horizontal: 12),
// width: 8,
// height: 8,
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// color: Colors.black12,
// ),
// ),
// if (widget.chartData.length > 1)
// widget.chartData.last.chestCircumference > widget.chartData[widget.chartData.length - 2].chestCircumference
// ? Icon(
// Icons.arrow_drop_up,
// size: 40,
// color: Colors.grey,
// )
// : Icon(
// Icons.arrow_drop_down,
// size: 40,
// color: Colors.grey,
// ),
// Text(
// '${widget.chartData.last.waistCircumference}',
// style: TextStyle(
// color: Colors.black,
// fontSize: 40,
// fontWeight: FontWeight.w500,
// ),
// ),
// if (widget.chartData.length == 1)
// Container(
// margin: EdgeInsets.symmetric(horizontal: 12),
// width: 8,
// height: 8,
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// color: Colors.black12,
// ),
// ),
// if (widget.chartData.length > 1)
// widget.chartData.last.waistCircumference > widget.chartData[widget.chartData.length - 2].waistCircumference
// ? Icon(
// Icons.arrow_drop_up,
// size: 40,
// color: Colors.grey,
// )
// : Icon(
// Icons.arrow_drop_down,
// size: 40,
// color: Colors.grey,
// ),
// Text(
// '${widget.chartData.last.hipCircumference}',
// style: TextStyle(
// color: Colors.black,
// fontSize: 40,
// fontWeight: FontWeight.w500,
// ),
// ),
// if (widget.chartData.length == 1)
// Container(
// margin: EdgeInsets.symmetric(horizontal: 12),
// width: 8,
// height: 8,
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// color: Colors.black12,
// ),
// ),
// if (widget.chartData.length > 1)
// widget.chartData.last.hipCircumference > widget.chartData[widget.chartData.length - 2].hipCircumference
// ? Icon(
// Icons.arrow_drop_up,
// size: 40,
// color: Colors.grey,
// )
// : Icon(
// Icons.arrow_drop_down,
// size: 40,
// color: Colors.grey,
// ),
// ],
// ),
// ),
// Stack(
// alignment: Alignment.bottomRight,
// children: [
// SfCartesianChart(
// margin: EdgeInsets.symmetric(horizontal: 8),
// enableAxisAnimation: true,
// plotAreaBorderWidth: 0,
// trackballBehavior: TrackballBehavior(
// enable: true,
// activationMode: ActivationMode.singleTap,
// tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
// tooltipSettings: InteractiveTooltip(),
// lineType: TrackballLineType.vertical,
// ),
// primaryXAxis: DateTimeCategoryAxis(
// tickPosition: TickPosition.inside,
// majorTickLines: MajorTickLines(
// size: 0,
// ),
// edgeLabelPlacement: EdgeLabelPlacement.shift,
// dateFormat: DateFormat.MMMd('ru'),
// labelStyle: TextStyle(
// color: Colors.grey,
// ),
// majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
// axisLine: AxisLine(
// color: Colors.grey.withOpacity(0.3),
// width: 0.4,
// ),
// ),
// primaryYAxis: NumericAxis(
// isVisible: false,
// labelFormat: '{value} см',
// axisLine: AxisLine(
// width: 1,
// ),
// majorTickLines: MajorTickLines(size: 0),
// ),
// series: _getSplineSeries(),
// tooltipBehavior: TooltipBehavior(enable: true),
// ),
// FloatingActionButton.small(
// heroTag: 'addCircumference',
// onPressed: () {
// if (widget.chartData.isNotEmpty) {
// chest = widget.chartData.last.chestCircumference;
// waist = widget.chartData.last.waistCircumference;
// hip = widget.chartData.last.hipCircumference;
// chestController = FixedExtentScrollController(initialItem: chest - 20);
// waistController = FixedExtentScrollController(initialItem: waist - 20);
// hipController = FixedExtentScrollController(initialItem: hip - 20);
// } else {
// chestController = FixedExtentScrollController();
// waistController = FixedExtentScrollController();
// hipController = FixedExtentScrollController();
// }
// showModalBottomSheet(
// useRootNavigator: true,
// context: context,
// builder: (context) {
// return Column(
// children: [
// Expanded(
// child: Row(
// children: [
// Expanded(
// child: CupertinoPicker(
// magnification: 1.22,
// squeeze: 1.2,
// useMagnifier: true,
// scrollController: chestController,
// itemExtent: 24,
// onSelectedItemChanged: (int value) {
// chest = value;
// },
// children: [
// for (int i = 20; i < 200; i++) Text('$i'),
// ],
// ),
// ),
// Expanded(
// child: CupertinoPicker(
// magnification: 1.22,
// squeeze: 1.2,
// useMagnifier: true,
// scrollController: waistController,
// itemExtent: 24,
// onSelectedItemChanged: (int value) {
// waist = value;
// },
// children: [
// for (int i = 20; i < 200; i++) Text('$i'),
// ],
// ),
// ),
// Expanded(
// child: CupertinoPicker(
// magnification: 1.22,
// squeeze: 1.2,
// useMagnifier: true,
// scrollController: hipController,
// itemExtent: 24,
// onSelectedItemChanged: (int value) {
// hip = value;
// },
// children: [
// for (int i = 20; i < 200; i++) Text('$i'),
// ],
// ),
// ),
// ],
// ),
// ),
// InkWell(
// onTap: () {
// widget.profileCubit.addCircumference(
// chestCircumference: chest,
// waistCircumference: waist,
// hipCircumference: hip,
// );
// Navigator.of(context).pop();
// },
// borderRadius: BorderRadius.circular(16),
// child: Ink(
// width: MediaQuery.of(context).size.width - 32,
// padding: EdgeInsets.all(16),
// decoration: BoxDecoration(
// color: appTheme.blueA400,
// borderRadius: BorderRadius.circular(16),
// ),
// child: Center(
// child: Text(
// 'Сохранить',
// style: TextStyle(
// color: Colors.white,
// ),
// ),
// ),
// ),
// ),
// ],
// );
// },
// );
// },
// backgroundColor: Colors.red,
// shape: CircleBorder(),
// child: Icon(
// Icons.add,
// color: Colors.white,
// ),
// ),
// ],
// ),
// ],
// );
// }
//
// List<CartesianSeries<Circumference, DateTime>> _getSplineSeries() {
// final Color seriesColor1 = Colors.red;
// final Color seriesColor2 = appTheme.blueA400;
// final Color seriesColor3 = Colors.green;
//
// return <CartesianSeries<Circumference, DateTime>>[
// SplineAreaSeries<Circumference, DateTime>(
// markerSettings: MarkerSettings(
// isVisible: true,
// color: seriesColor1,
// height: 8,
// width: 8,
// ),
// dataLabelSettings: DataLabelSettings(
// labelAlignment: ChartDataLabelAlignment.top,
// isVisible: true,
// ),
// dataSource: widget.chartData,
// borderColor: seriesColor1,
// gradient: LinearGradient(
// colors: [
// seriesColor1.withOpacity(0.14),
// Colors.transparent,
// ],
// begin: Alignment.topCenter,
// end: Alignment(0, 0.6),
// ),
// name: 'Грудь',
// xValueMapper: (Circumference value, int index) => value.createdAt,
// yValueMapper: (Circumference value, int index) => value.chestCircumference,
// ),
// SplineAreaSeries<Circumference, DateTime>(
// markerSettings: MarkerSettings(
// isVisible: true,
// color: seriesColor2,
// height: 8,
// width: 8,
// ),
// dataLabelSettings: DataLabelSettings(
// labelAlignment: ChartDataLabelAlignment.top,
// isVisible: true,
// ),
// dataSource: widget.chartData,
// borderColor: seriesColor2,
// gradient: LinearGradient(
// colors: [
// seriesColor2.withOpacity(0.14),
// Colors.transparent,
// ],
// begin: Alignment.topCenter,
// end: Alignment(0, 0.6),
// ),
// name: 'Талия',
// xValueMapper: (Circumference value, int index) => value.createdAt,
// yValueMapper: (Circumference value, int index) => value.waistCircumference,
// ),
// SplineAreaSeries<Circumference, DateTime>(
// markerSettings: MarkerSettings(
// isVisible: true,
// color: seriesColor3,
// height: 8,
// width: 8,
// ),
// dataLabelSettings: DataLabelSettings(
// labelAlignment: ChartDataLabelAlignment.top,
// isVisible: true,
// ),
// dataSource: widget.chartData,
// borderColor: seriesColor3,
// gradient: LinearGradient(
// colors: [
// seriesColor3.withOpacity(0.14),
// Colors.transparent,
// ],
// begin: Alignment.topCenter,
// end: Alignment(0, 0.6),
// ),
// name: 'Бёдра',
// xValueMapper: (Circumference value, int index) => value.createdAt,
// yValueMapper: (Circumference value, int index) => value.hipCircumference,
// ),
// ];
// }
// }

View File

@@ -1,114 +1,114 @@
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/theme/theme_helper.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:intl/intl.dart';
class ImtChartWidget extends StatelessWidget {
final List<ChartPointModel> chartPoints;
const ImtChartWidget({
super.key,
required this.chartPoints,
});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'${chartPoints.last.bmi.toStringAsFixed(2)}',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.w500,
),
),
chartPoints.last.bmi > chartPoints[chartPoints.length - 2].bmi
? Icon(
Icons.arrow_drop_up,
size: 40,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 40,
color: Colors.grey,
),
],
),
),
SfCartesianChart(
margin: EdgeInsets.symmetric(horizontal: 8),
enableAxisAnimation: true,
plotAreaBorderWidth: 0,
trackballBehavior: TrackballBehavior(
enable: true,
activationMode: ActivationMode.singleTap,
tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
tooltipSettings: InteractiveTooltip(),
lineType: TrackballLineType.vertical,
),
primaryXAxis: DateTimeCategoryAxis(
initialVisibleMinimum: chartPoints.first.createdAt,
initialVisibleMaximum: chartPoints.last.createdAt,
tickPosition: TickPosition.inside,
majorTickLines: MajorTickLines(
size: 0,
),
edgeLabelPlacement: EdgeLabelPlacement.shift,
dateFormat: DateFormat.MMMd('ru'),
labelStyle: TextStyle(
color: Colors.grey,
),
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
axisLine: AxisLine(
color: Colors.grey.withOpacity(0.3),
width: 0.4,
),
),
primaryYAxis: NumericAxis(
isVisible: false,
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
],
);
}
List<CartesianSeries<ChartPointModel, DateTime>> _getSplineSeries() {
return <CartesianSeries<ChartPointModel, DateTime>>[
SplineAreaSeries<ChartPointModel, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: appTheme.blueA400,
height: 8,
width: 8,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: chartPoints,
borderColor: appTheme.blueA400,
gradient: LinearGradient(
colors: [
appTheme.blueA400.withOpacity(0.14),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment(0, 0.6),
),
name: 'ИМТ',
xValueMapper: (ChartPointModel value, int index) => value.createdAt,
yValueMapper: (ChartPointModel value, int index) => double.parse(value.bmi.toStringAsFixed(2)),
),
];
}
}
// import 'package:eatvio_app/features/profile/models/profile_model.dart';
// import 'package:eatvio_app/theme/theme_helper.dart';
// import 'package:flutter/material.dart';
// import 'package:syncfusion_flutter_charts/charts.dart';
// import 'package:intl/intl.dart';
//
// class ImtChartWidget extends StatelessWidget {
// final List<ChartPointModel> chartPoints;
//
// const ImtChartWidget({
// super.key,
// required this.chartPoints,
// });
//
// @override
// Widget build(BuildContext context) {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
// child: Row(
// children: [
// Text(
// '${chartPoints.last.bmi.toStringAsFixed(2)}',
// style: TextStyle(
// color: Colors.black,
// fontSize: 40,
// fontWeight: FontWeight.w500,
// ),
// ),
// chartPoints.last.bmi > chartPoints[chartPoints.length - 2].bmi
// ? Icon(
// Icons.arrow_drop_up,
// size: 40,
// color: Colors.grey,
// )
// : Icon(
// Icons.arrow_drop_down,
// size: 40,
// color: Colors.grey,
// ),
// ],
// ),
// ),
// SfCartesianChart(
// margin: EdgeInsets.symmetric(horizontal: 8),
// enableAxisAnimation: true,
// plotAreaBorderWidth: 0,
// trackballBehavior: TrackballBehavior(
// enable: true,
// activationMode: ActivationMode.singleTap,
// tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
// tooltipSettings: InteractiveTooltip(),
// lineType: TrackballLineType.vertical,
// ),
// primaryXAxis: DateTimeCategoryAxis(
// initialVisibleMinimum: chartPoints.first.createdAt,
// initialVisibleMaximum: chartPoints.last.createdAt,
// tickPosition: TickPosition.inside,
// majorTickLines: MajorTickLines(
// size: 0,
// ),
// edgeLabelPlacement: EdgeLabelPlacement.shift,
// dateFormat: DateFormat.MMMd('ru'),
// labelStyle: TextStyle(
// color: Colors.grey,
// ),
// majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
// axisLine: AxisLine(
// color: Colors.grey.withOpacity(0.3),
// width: 0.4,
// ),
// ),
// primaryYAxis: NumericAxis(
// isVisible: false,
// ),
// series: _getSplineSeries(),
// tooltipBehavior: TooltipBehavior(enable: true),
// ),
// ],
// );
// }
//
// List<CartesianSeries<ChartPointModel, DateTime>> _getSplineSeries() {
// return <CartesianSeries<ChartPointModel, DateTime>>[
// SplineAreaSeries<ChartPointModel, DateTime>(
// markerSettings: MarkerSettings(
// isVisible: true,
// color: appTheme.blueA400,
// height: 8,
// width: 8,
// ),
// dataLabelSettings: DataLabelSettings(
// labelAlignment: ChartDataLabelAlignment.top,
// isVisible: true,
// ),
// dataSource: chartPoints,
// borderColor: appTheme.blueA400,
// gradient: LinearGradient(
// colors: [
// appTheme.blueA400.withOpacity(0.14),
// Colors.transparent,
// ],
// begin: Alignment.topCenter,
// end: Alignment(0, 0.6),
// ),
// name: 'ИМТ',
// xValueMapper: (ChartPointModel value, int index) => value.createdAt,
// yValueMapper: (ChartPointModel value, int index) => double.parse(value.bmi.toStringAsFixed(2)),
// ),
// ];
// }
// }

View File

@@ -1,237 +1,237 @@
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class WeightChartWidget extends StatefulWidget {
final List<ChartPointModel> chartPoints;
final ProfileCubit profileCubit;
const WeightChartWidget({
super.key,
required this.chartPoints,
required this.profileCubit,
});
@override
State<WeightChartWidget> createState() => _WeightChartWidgetState();
}
class _WeightChartWidgetState extends State<WeightChartWidget> {
late FixedExtentScrollController weightKiloController;
late FixedExtentScrollController weightGramsController;
late int weightKilo;
late int weightGrams;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (widget.chartPoints.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'${widget.chartPoints.last.weight.toStringAsFixed(1)} кг',
style: TextStyle(
color: Colors.black,
fontSize: 40,
fontWeight: FontWeight.w500,
),
),
if (widget.chartPoints.length == 1)
Container(
margin: EdgeInsets.symmetric(horizontal: 12),
width: 8,
height: 8,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black12,
),
),
if (widget.chartPoints.length > 1) widget.chartPoints.last.weight > widget.chartPoints[widget.chartPoints.length - 2].weight
? Icon(
Icons.arrow_drop_up,
size: 40,
color: Colors.grey.withOpacity(0.4),
)
: Icon(
Icons.arrow_drop_down,
size: 40,
color: Colors.grey.withOpacity(0.4),
),
],
),
),
Stack(
alignment: Alignment.bottomRight,
children: [
SfCartesianChart(
margin: EdgeInsets.symmetric(horizontal: 8),
enableAxisAnimation: true,
plotAreaBorderWidth: 0,
trackballBehavior: TrackballBehavior(
enable: true,
activationMode: ActivationMode.singleTap,
tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
tooltipSettings: InteractiveTooltip(),
lineType: TrackballLineType.vertical,
),
primaryXAxis: DateTimeCategoryAxis(
tickPosition: TickPosition.inside,
majorTickLines: MajorTickLines(
size: 0,
),
edgeLabelPlacement: EdgeLabelPlacement.shift,
dateFormat: DateFormat.MMMd('ru'),
labelStyle: TextStyle(
color: Colors.grey,
),
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
axisLine: AxisLine(
color: Colors.grey.withOpacity(0.3),
width: 0.4,
),
),
primaryYAxis: NumericAxis(
isVisible: false,
labelFormat: '{value} кг',
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey),
axisLine: AxisLine(
width: 1,
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
FloatingActionButton.small(
heroTag: 'addWeight',
onPressed: () {
if (widget.chartPoints.isNotEmpty) {
weightKilo = int.parse(widget.chartPoints.last.weight.toString().split('.')[0]);
weightGrams = int.parse(widget.chartPoints.last.weight.toString().split('.')[1][0]);
weightKiloController = FixedExtentScrollController(initialItem: weightKilo - 20);
weightGramsController = FixedExtentScrollController(initialItem: weightGrams);
} else {
weightKiloController = FixedExtentScrollController();
weightGramsController = FixedExtentScrollController();
}
showModalBottomSheet(
useRootNavigator: true,
context: context,
builder: (context) {
return Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
scrollController: weightKiloController,
itemExtent: 24,
onSelectedItemChanged: (int value) {
weightKilo = value + 20;
},
children: [
for (int i = 20; i < 300; i++) Text('$i'),
],
),
),
Expanded(
child: CupertinoPicker(
magnification: 1.22,
squeeze: 1.2,
useMagnifier: true,
scrollController: weightGramsController,
itemExtent: 24,
onSelectedItemChanged: (int value) {
weightGrams = value;
},
children: [
for (int i = 0; i < 10; i++) Text('$i'),
],
),
),
],
),
),
InkWell(
onTap: () {
widget.profileCubit.addWeight(weight: double.parse('$weightKilo.$weightGrams'));
Navigator.of(context).pop();
},
borderRadius: BorderRadius.circular(16),
child: Ink(
width: MediaQuery.of(context).size.width - 32,
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: BorderRadius.circular(16),
),
child: Center(
child: Text(
'Сохранить',
style: TextStyle(
color: Colors.white,
),
),
),
),
),
],
);
},
);
},
backgroundColor: Colors.red,
shape: CircleBorder(),
child: Icon(
Icons.add,
color: Colors.white,
),
),
],
),
],
);
}
List<CartesianSeries<ChartPointModel, DateTime>> _getSplineSeries() {
return <CartesianSeries<ChartPointModel, DateTime>>[
SplineAreaSeries<ChartPointModel, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: appTheme.blueA400,
height: 8,
width: 8,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: widget.chartPoints,
borderColor: appTheme.blueA400,
gradient: LinearGradient(
colors: [
appTheme.blueA400.withOpacity(0.14),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment(0, 0.6),
),
name: 'Вес',
xValueMapper: (ChartPointModel value, int index) => value.createdAt,
yValueMapper: (ChartPointModel value, int index) => value.weight,
),
];
}
}
// import 'package:eatvio_app/core/app_export.dart';
// import 'package:eatvio_app/features/profile/models/profile_model.dart';
// import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
// import 'package:flutter/cupertino.dart';
// import 'package:flutter/material.dart';
// import 'package:intl/intl.dart';
// import 'package:syncfusion_flutter_charts/charts.dart';
//
// class WeightChartWidget extends StatefulWidget {
// final List<ChartPointModel> chartPoints;
// final ProfileCubit profileCubit;
//
// const WeightChartWidget({
// super.key,
// required this.chartPoints,
// required this.profileCubit,
// });
//
// @override
// State<WeightChartWidget> createState() => _WeightChartWidgetState();
// }
//
// class _WeightChartWidgetState extends State<WeightChartWidget> {
// late FixedExtentScrollController weightKiloController;
// late FixedExtentScrollController weightGramsController;
// late int weightKilo;
// late int weightGrams;
//
// @override
// Widget build(BuildContext context) {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// if (widget.chartPoints.isNotEmpty)
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
// child: Row(
// children: [
// Text(
// '${widget.chartPoints.last.weight.toStringAsFixed(1)} кг',
// style: TextStyle(
// color: Colors.black,
// fontSize: 40,
// fontWeight: FontWeight.w500,
// ),
// ),
// if (widget.chartPoints.length == 1)
// Container(
// margin: EdgeInsets.symmetric(horizontal: 12),
// width: 8,
// height: 8,
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// color: Colors.black12,
// ),
// ),
// if (widget.chartPoints.length > 1) widget.chartPoints.last.weight > widget.chartPoints[widget.chartPoints.length - 2].weight
// ? Icon(
// Icons.arrow_drop_up,
// size: 40,
// color: Colors.grey.withOpacity(0.4),
// )
// : Icon(
// Icons.arrow_drop_down,
// size: 40,
// color: Colors.grey.withOpacity(0.4),
// ),
// ],
// ),
// ),
// Stack(
// alignment: Alignment.bottomRight,
// children: [
// SfCartesianChart(
// margin: EdgeInsets.symmetric(horizontal: 8),
// enableAxisAnimation: true,
// plotAreaBorderWidth: 0,
// trackballBehavior: TrackballBehavior(
// enable: true,
// activationMode: ActivationMode.singleTap,
// tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
// tooltipSettings: InteractiveTooltip(),
// lineType: TrackballLineType.vertical,
// ),
// primaryXAxis: DateTimeCategoryAxis(
// tickPosition: TickPosition.inside,
// majorTickLines: MajorTickLines(
// size: 0,
// ),
// edgeLabelPlacement: EdgeLabelPlacement.shift,
// dateFormat: DateFormat.MMMd('ru'),
// labelStyle: TextStyle(
// color: Colors.grey,
// ),
// majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)),
// axisLine: AxisLine(
// color: Colors.grey.withOpacity(0.3),
// width: 0.4,
// ),
// ),
// primaryYAxis: NumericAxis(
// isVisible: false,
// labelFormat: '{value} кг',
// majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey),
// axisLine: AxisLine(
// width: 1,
// ),
// majorTickLines: MajorTickLines(size: 0),
// ),
// series: _getSplineSeries(),
// tooltipBehavior: TooltipBehavior(enable: true),
// ),
// FloatingActionButton.small(
// heroTag: 'addWeight',
// onPressed: () {
// if (widget.chartPoints.isNotEmpty) {
// weightKilo = int.parse(widget.chartPoints.last.weight.toString().split('.')[0]);
// weightGrams = int.parse(widget.chartPoints.last.weight.toString().split('.')[1][0]);
// weightKiloController = FixedExtentScrollController(initialItem: weightKilo - 20);
// weightGramsController = FixedExtentScrollController(initialItem: weightGrams);
// } else {
// weightKiloController = FixedExtentScrollController();
// weightGramsController = FixedExtentScrollController();
// }
// showModalBottomSheet(
// useRootNavigator: true,
// context: context,
// builder: (context) {
// return Column(
// children: [
// Expanded(
// child: Row(
// children: [
// Expanded(
// child: CupertinoPicker(
// magnification: 1.22,
// squeeze: 1.2,
// useMagnifier: true,
// scrollController: weightKiloController,
// itemExtent: 24,
// onSelectedItemChanged: (int value) {
// weightKilo = value + 20;
// },
// children: [
// for (int i = 20; i < 300; i++) Text('$i'),
// ],
// ),
// ),
// Expanded(
// child: CupertinoPicker(
// magnification: 1.22,
// squeeze: 1.2,
// useMagnifier: true,
// scrollController: weightGramsController,
// itemExtent: 24,
// onSelectedItemChanged: (int value) {
// weightGrams = value;
// },
// children: [
// for (int i = 0; i < 10; i++) Text('$i'),
// ],
// ),
// ),
// ],
// ),
// ),
// InkWell(
// onTap: () {
// widget.profileCubit.addWeight(weight: double.parse('$weightKilo.$weightGrams'));
// Navigator.of(context).pop();
// },
// borderRadius: BorderRadius.circular(16),
// child: Ink(
// width: MediaQuery.of(context).size.width - 32,
// padding: EdgeInsets.all(16),
// decoration: BoxDecoration(
// color: appTheme.blueA400,
// borderRadius: BorderRadius.circular(16),
// ),
// child: Center(
// child: Text(
// 'Сохранить',
// style: TextStyle(
// color: Colors.white,
// ),
// ),
// ),
// ),
// ),
// ],
// );
// },
// );
// },
// backgroundColor: Colors.red,
// shape: CircleBorder(),
// child: Icon(
// Icons.add,
// color: Colors.white,
// ),
// ),
// ],
// ),
// ],
// );
// }
//
// List<CartesianSeries<ChartPointModel, DateTime>> _getSplineSeries() {
// return <CartesianSeries<ChartPointModel, DateTime>>[
// SplineAreaSeries<ChartPointModel, DateTime>(
// markerSettings: MarkerSettings(
// isVisible: true,
// color: appTheme.blueA400,
// height: 8,
// width: 8,
// ),
// dataLabelSettings: DataLabelSettings(
// labelAlignment: ChartDataLabelAlignment.top,
// isVisible: true,
// ),
// dataSource: widget.chartPoints,
// borderColor: appTheme.blueA400,
// gradient: LinearGradient(
// colors: [
// appTheme.blueA400.withOpacity(0.14),
// Colors.transparent,
// ],
// begin: Alignment.topCenter,
// end: Alignment(0, 0.6),
// ),
// name: 'Вес',
// xValueMapper: (ChartPointModel value, int index) => value.createdAt,
// yValueMapper: (ChartPointModel value, int index) => value.weight,
// ),
// ];
// }
// }