forked from eatvio/eatvio_app
128 lines
4.4 KiB
Dart
128 lines
4.4 KiB
Dart
import 'package:eatvio_app/features/profile/models/weight_model.dart';
|
|
import 'package:eatvio_app/core/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<WeightModel> weightPoints;
|
|
|
|
const ImtChartWidget({
|
|
super.key,
|
|
required this.weightPoints,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Row(
|
|
children: [
|
|
if (weightPoints.isNotEmpty)
|
|
Text(
|
|
weightPoints.last.bmi.toStringAsFixed(2),
|
|
style: const TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 40,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
if (weightPoints.length > 1)
|
|
weightPoints.last.bmi > weightPoints[weightPoints.length - 2].bmi
|
|
? const Icon(
|
|
Icons.arrow_drop_up,
|
|
size: 40,
|
|
color: Colors.grey,
|
|
)
|
|
: const Icon(
|
|
Icons.arrow_drop_down,
|
|
size: 40,
|
|
color: Colors.grey,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
SfCartesianChart(
|
|
margin: const EdgeInsets.symmetric(horizontal: 8),
|
|
enableAxisAnimation: true,
|
|
plotAreaBorderWidth: 0,
|
|
trackballBehavior: TrackballBehavior(
|
|
enable: true,
|
|
activationMode: ActivationMode.singleTap,
|
|
tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
|
|
tooltipSettings: const InteractiveTooltip(),
|
|
lineType: TrackballLineType.vertical,
|
|
),
|
|
primaryXAxis: DateTimeCategoryAxis(
|
|
tickPosition: TickPosition.inside,
|
|
majorTickLines: const MajorTickLines(
|
|
size: 0,
|
|
),
|
|
edgeLabelPlacement: EdgeLabelPlacement.shift,
|
|
dateFormat: DateFormat.MMMd('ru'),
|
|
labelStyle: const TextStyle(
|
|
color: Colors.grey,
|
|
),
|
|
majorGridLines: MajorGridLines(dashArray: const [1], color: Colors.grey.withValues(alpha: 0.3)),
|
|
axisLine: AxisLine(
|
|
color: Colors.grey.withValues(alpha: 0.3),
|
|
width: 0.4,
|
|
),
|
|
),
|
|
primaryYAxis: const NumericAxis(
|
|
isVisible: false,
|
|
),
|
|
series: _getSplineSeries(),
|
|
tooltipBehavior: TooltipBehavior(enable: true),
|
|
),
|
|
if (weightPoints.isEmpty)
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 32),
|
|
child: Text(
|
|
'Индекс Массы Тела рассчитывается при указанных весе и росте',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
List<CartesianSeries<WeightModel, DateTime>> _getSplineSeries() {
|
|
return <CartesianSeries<WeightModel, DateTime>>[
|
|
SplineAreaSeries<WeightModel, DateTime>(
|
|
markerSettings: MarkerSettings(
|
|
isVisible: true,
|
|
color: appTheme.blueA400,
|
|
height: 8,
|
|
width: 8,
|
|
),
|
|
dataLabelSettings: const DataLabelSettings(
|
|
labelAlignment: ChartDataLabelAlignment.top,
|
|
isVisible: true,
|
|
),
|
|
dataSource: weightPoints,
|
|
borderColor: appTheme.blueA400,
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
appTheme.blueA400.withValues(alpha: 0.14),
|
|
Colors.transparent,
|
|
],
|
|
begin: Alignment.topCenter,
|
|
end: const Alignment(0, 0.6),
|
|
),
|
|
name: 'ИМТ',
|
|
xValueMapper: (WeightModel value, int index) => value.createdAt,
|
|
yValueMapper: (WeightModel value, int index) => double.parse(value.bmi.toStringAsFixed(2)),
|
|
),
|
|
];
|
|
}
|
|
}
|