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 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.length > 0) Text( '${weightPoints.last.bmi.toStringAsFixed(2)}', style: TextStyle( color: Colors.black, fontSize: 40, fontWeight: FontWeight.w500, ), ), if (weightPoints.length > 1) weightPoints.last.bmi > weightPoints[weightPoints.length - 2].bmi ? Icon( Icons.arrow_drop_up, size: 40, color: Colors.grey, ) : Icon( Icons.arrow_drop_down, size: 40, color: Colors.grey, ), ], ), ), Stack( alignment: Alignment.center, 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.withValues(alpha: 0.3)), axisLine: AxisLine( color: Colors.grey.withValues(alpha: 0.3), width: 0.4, ), ), primaryYAxis: NumericAxis( isVisible: false, ), series: _getSplineSeries(), tooltipBehavior: TooltipBehavior(enable: true), ), if (weightPoints.isEmpty) Padding( padding: const EdgeInsets.symmetric(horizontal: 32), child: Text( 'Индекс Массы Тела рассчитывается при указанных весе и росте', textAlign: TextAlign.center, ), ), ], ), ], ); } List> _getSplineSeries() { return >[ SplineAreaSeries( markerSettings: MarkerSettings( isVisible: true, color: appTheme.blueA400, height: 8, width: 8, ), dataLabelSettings: 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: Alignment(0, 0.6), ), name: 'ИМТ', xValueMapper: (WeightModel value, int index) => value.createdAt, yValueMapper: (WeightModel value, int index) => double.parse(value.bmi.toStringAsFixed(2)), ), ]; } }