Files
eatvio_app/lib/features/profile/presentation/widgets/circumference_chart_widget.dart
2024-08-30 16:36:22 +03:00

176 lines
5.7 KiB
Dart

import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
class CircumferenceChartWidget extends StatelessWidget {
final List<Circumference> chartData;
const CircumferenceChartWidget({
super.key,
required this.chartData,
});
@override
Widget build(BuildContext context) {
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Text(
'Грудь ${chartData.last.chestCircumference} см',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
chartData.last.chestCircumference > chartData[chartData.length - 2].chestCircumference
? Icon(
Icons.arrow_drop_up,
size: 18,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey,
),
Text(
'Талия ${chartData.last.waistCircumference} см',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
chartData.last.waistCircumference > chartData[chartData.length - 2].waistCircumference
? Icon(
Icons.arrow_drop_up,
size: 18,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey,
),
Text(
'Бёдра ${chartData.last.hipCircumference} см',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
chartData.last.hipCircumference > chartData[chartData.length - 2].hipCircumference
? Icon(
Icons.arrow_drop_up,
size: 18,
color: Colors.grey,
)
: Icon(
Icons.arrow_drop_down,
size: 18,
color: Colors.grey,
),
],
),
),
SfCartesianChart(
margin: EdgeInsets.zero,
enableAxisAnimation: true,
enableSideBySideSeriesPlacement: true,
legend: const Legend(
isVisible: true,
opacity: 0.7,
position: LegendPosition.bottom,
),
plotAreaBorderWidth: 0,
trackballBehavior: TrackballBehavior(
enable: true,
activationMode: ActivationMode.singleTap,
),
primaryXAxis: DateTimeCategoryAxis(
dateFormat: DateFormat.MMMd('ru'),
axisLine: AxisLine(
width: 1,
),
),
primaryYAxis: NumericAxis(
labelFormat: '{value} см',
axisLine: AxisLine(
width: 1,
),
majorTickLines: MajorTickLines(size: 0),
),
series: _getSplineSeries(),
tooltipBehavior: TooltipBehavior(enable: true),
),
],
);
}
List<CartesianSeries<Circumference, DateTime>> _getSplineSeries() {
final Color seriesColor1 = Colors.red;
final Color seriesColor2 = Colors.blue;
final Color seriesColor3 = Colors.green;
return <CartesianSeries<Circumference, DateTime>>[
SplineSeries<Circumference, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: seriesColor1,
height: 12,
width: 12,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: chartData,
color: seriesColor1,
name: 'Грудь',
xValueMapper: (Circumference value, int index) => value.createdAt,
yValueMapper: (Circumference value, int index) => value.chestCircumference,
),
SplineSeries<Circumference, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: seriesColor2,
height: 12,
width: 12,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: chartData,
color: seriesColor2,
name: 'Талия',
xValueMapper: (Circumference value, int index) => value.createdAt,
yValueMapper: (Circumference value, int index) => value.waistCircumference,
),
SplineSeries<Circumference, DateTime>(
markerSettings: MarkerSettings(
isVisible: true,
color: seriesColor3,
height: 12,
width: 12,
),
dataLabelSettings: DataLabelSettings(
labelAlignment: ChartDataLabelAlignment.top,
isVisible: true,
),
dataSource: chartData,
color: seriesColor3,
name: 'Бёдра',
xValueMapper: (Circumference value, int index) => value.createdAt,
yValueMapper: (Circumference value, int index) => value.hipCircumference,
),
];
}
}