98 lines
2.9 KiB
Dart
98 lines
2.9 KiB
Dart
import 'package:fl_chart/fl_chart.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../../core/constants/app_colors.dart';
|
|
|
|
class ActivityChart extends StatelessWidget {
|
|
final List<Map<String, dynamic>> data;
|
|
|
|
const ActivityChart({super.key, required this.data});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: 300,
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: LineChart(
|
|
LineChartData(
|
|
gridData: FlGridData(
|
|
show: true,
|
|
drawVerticalLine: true,
|
|
getDrawingHorizontalLine: (value) {
|
|
return FlLine(
|
|
color: Colors.grey.withOpacity(0.2),
|
|
strokeWidth: 1,
|
|
dashArray: [5, 5],
|
|
);
|
|
},
|
|
getDrawingVerticalLine: (value) {
|
|
return FlLine(
|
|
color: Colors.grey.withOpacity(0.2),
|
|
strokeWidth: 1,
|
|
dashArray: [5, 5],
|
|
);
|
|
},
|
|
),
|
|
titlesData: FlTitlesData(show: false),
|
|
borderData: FlBorderData(show: false),
|
|
minX: 0,
|
|
maxX: 30,
|
|
minY: 0,
|
|
maxY: 100,
|
|
lineBarsData: [
|
|
LineChartBarData(
|
|
spots: data
|
|
.map(
|
|
(e) => FlSpot(
|
|
(e['day'] as int).toDouble(),
|
|
(e['value'] as int).toDouble(),
|
|
),
|
|
)
|
|
.toList(),
|
|
isCurved: true,
|
|
color: AppColors.primary,
|
|
barWidth: 3,
|
|
isStrokeCapRound: true,
|
|
dotData: FlDotData(show: true),
|
|
belowBarData: BarAreaData(
|
|
show: true,
|
|
color: AppColors.primary.withOpacity(0.1),
|
|
),
|
|
),
|
|
// Add a second dummy line to match the complex look of the image roughly
|
|
LineChartBarData(
|
|
spots: data
|
|
.map(
|
|
(e) => FlSpot(
|
|
(e['day'] as int).toDouble(),
|
|
100 - (e['value'] as int).toDouble(),
|
|
),
|
|
)
|
|
.toList(),
|
|
isCurved: true,
|
|
color: AppColors.secondary,
|
|
barWidth: 3,
|
|
isStrokeCapRound: true,
|
|
dotData: FlDotData(show: true),
|
|
belowBarData: BarAreaData(
|
|
show: true,
|
|
color: AppColors.secondary.withOpacity(0.1),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|