forked from eatvio/eatvio_app
96 lines
2.9 KiB
Dart
96 lines
2.9 KiB
Dart
import 'package:eatvio_app/features/profile/models/profile_model.dart' as ProfileModel;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class ImtChartWidget extends StatelessWidget {
|
|
final List<ProfileModel.ChartPoint> 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: 48,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
chartPoints.last.bmi > chartPoints[chartPoints.length - 2].bmi
|
|
? Icon(
|
|
Icons.arrow_drop_up,
|
|
size: 48,
|
|
color: Colors.grey,
|
|
)
|
|
: Icon(
|
|
Icons.arrow_drop_down,
|
|
size: 48,
|
|
color: Colors.grey,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SfCartesianChart(
|
|
margin: EdgeInsets.zero,
|
|
enableAxisAnimation: true,
|
|
enableSideBySideSeriesPlacement: true,
|
|
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<ProfileModel.ChartPoint, DateTime>> _getSplineSeries() {
|
|
return <CartesianSeries<ProfileModel.ChartPoint, DateTime>>[
|
|
SplineSeries<ProfileModel.ChartPoint, DateTime>(
|
|
markerSettings: MarkerSettings(
|
|
isVisible: true,
|
|
color: Colors.blue,
|
|
height: 12,
|
|
width: 12,
|
|
),
|
|
dataLabelSettings: DataLabelSettings(
|
|
labelAlignment: ChartDataLabelAlignment.top,
|
|
isVisible: true,
|
|
),
|
|
dataSource: chartPoints,
|
|
color: Colors.blue,
|
|
name: 'ИМТ',
|
|
xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt,
|
|
yValueMapper: (ProfileModel.ChartPoint value, int index) => value.bmi,
|
|
),
|
|
];
|
|
}
|
|
}
|