You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/lib/presentation/smartwatches/widgets/health_chart.dart

88 lines
2.6 KiB
Dart

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
class HealthChart extends StatelessWidget {
final List<FlSpot> spots;
final String title;
final Color gradientColor;
const HealthChart({
Key? key,
required this.spots,
required this.title,
required this.gradientColor,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: 200,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 5,
blurRadius: 7,
offset: const Offset(0, 3),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
Expanded(
child: LineChart(
LineChartData(
gridData: FlGridData(show: false),
titlesData: FlTitlesData(show: false),
borderData: FlBorderData(show: false),
minX: 0,
maxX: spots.length.toDouble() - 1,
minY: spots.map((e) => e.y).reduce((a, b) => a < b ? a : b),
maxY: spots.map((e) => e.y).reduce((a, b) => a > b ? a : b),
lineBarsData: [
LineChartBarData(
spots: spots,
isCurved: true,
gradient: LinearGradient(
colors: [
gradientColor.withOpacity(0.5),
gradientColor,
],
),
barWidth: 3,
isStrokeCapRound: true,
dotData: FlDotData(show: false),
belowBarData: BarAreaData(
show: true,
gradient: LinearGradient(
colors: [
gradientColor.withOpacity(0.1),
gradientColor.withOpacity(0.2),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
],
),
),
),
],
),
);
}
}