forked from eatvio/eatvio_app
121 lines
4.0 KiB
Dart
121 lines
4.0 KiB
Dart
import 'package:eatvio_app/core/app_export.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 WeightChartWidget extends StatelessWidget {
|
||
final List<ChartPointModel> chartPoints;
|
||
|
||
const WeightChartWidget({
|
||
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.weight.toStringAsFixed(2)} кг',
|
||
style: TextStyle(
|
||
color: Colors.black,
|
||
fontSize: 48,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
chartPoints.last.weight > chartPoints[chartPoints.length - 2].weight
|
||
? Icon(
|
||
Icons.arrow_drop_up,
|
||
size: 48,
|
||
color: Colors.grey.withOpacity(0.4),
|
||
)
|
||
: Icon(
|
||
Icons.arrow_drop_down,
|
||
size: 48,
|
||
color: Colors.grey.withOpacity(0.4),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
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,
|
||
labelFormat: '{value} кг',
|
||
majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey),
|
||
axisLine: AxisLine(
|
||
width: 1,
|
||
),
|
||
majorTickLines: MajorTickLines(size: 0),
|
||
),
|
||
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) => value.weight,
|
||
),
|
||
];
|
||
}
|
||
}
|