shows tooltip with data.

This commit is contained in:
Faris Armoush
2025-06-01 13:27:35 +03:00
parent e28f3c3c03
commit 066f967cd1

View File

@ -1,5 +1,6 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:syncrow_web/pages/analytics/models/air_quality_data_model.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/helpers/energy_management_charts_helper.dart';
import 'package:syncrow_web/utils/color_manager.dart';
@ -171,28 +172,64 @@ class AqiDistributionChart extends StatelessWidget {
tooltipPadding: const EdgeInsets.all(8),
getTooltipItem: (group, groupIndex, rod, rodIndex) {
final data = chartData[group.x.toInt()];
final stackItems = rod.rodStackItems;
final List<TextSpan> children = [];
final textStyle = context.textTheme.bodySmall?.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
);
if (data.good != null) {
children.add(TextSpan(
text: '\nGOOD: ${data.good!.toStringAsFixed(1)}%',
style: textStyle,
));
}
if (data.moderate != null) {
children.add(TextSpan(
text: '\nMODERATE: ${data.moderate!.toStringAsFixed(1)}%',
style: textStyle,
));
}
if (data.poor != null) {
children.add(TextSpan(
text: '\nPOOR: ${data.poor!.toStringAsFixed(1)}%',
style: textStyle,
));
}
if (data.unhealthy != null) {
children.add(TextSpan(
text: '\nUNHEALTHY: ${data.unhealthy!.toStringAsFixed(1)}%',
style: textStyle,
));
}
if (data.severe != null) {
children.add(TextSpan(
text: '\nSEVERE: ${data.severe!.toStringAsFixed(1)}%',
style: textStyle,
));
}
if (data.hazardous != null) {
children.add(TextSpan(
text: '\nHAZARDOUS: ${data.hazardous!.toStringAsFixed(1)}%',
style: textStyle,
));
}
return BarTooltipItem(
'${data.date.day}/${data.date.month}\n',
DateFormat('dd/MM/yyyy').format(data.date),
context.textTheme.bodyMedium!.copyWith(
color: ColorsManager.blackColor,
fontSize: 14,
fontSize: 16,
fontWeight: FontWeight.w600,
),
children: stackItems.map((item) {
final metricName = AirQualityDataModel.metricColors.entries
.firstWhere((entry) => entry.value == item.color)
.key
.toLowerCase();
return TextSpan(
text:
'$metricName: ${(item.toY - item.fromY).toStringAsFixed(1)}%\n',
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.blackColor,
fontSize: 12,
),
);
}).toList(),
children: children,
);
},
),