-
Sara Savanovic Djordjevic authoredSara Savanovic Djordjevic authored
bar_data.dart 5.76 KiB
import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';
import '../consts.dart';
import '../utils/format_month.dart';
class BarData extends StatefulWidget {
const BarData({super.key});
@override
State<StatefulWidget> createState() => _BarDataState();
}
class _BarDataState extends State<BarData> {
static const double barWidth = 30;
// Allocate bar data dynamically from selected subdivision
var barData = <int, List<double>>{};
double totalHeight = 0.5; // Set minimum total height
int touchedIndex = -1;
@override
void initState() {
super.initState();
// Allocate bar data dynamically based from the selected subdivision
for (int i = 0; i < 7; i++) {
var entry = selectedSubDiv?.iceStats[i];
if (entry != null) {
barData[i] = [
entry.slushIce,
entry.blackIce,
entry.snowDepth,
];
// Find tallest layer
if (entry.totalIce > totalHeight) {
totalHeight = entry.totalIce;
}
} else {
barData[i] = [0.0, 0.0, 0.0];
}
}
}
BarChartGroupData generateGroup(
int x,
double value1,
double value2,
double value3,
) {
final sum = value1 + value2 + value3;
final isTouched = touchedIndex == x;
return BarChartGroupData(
x: x,
showingTooltipIndicators: isTouched ? [0] : [],
barRods: [
BarChartRodData(
y: sum,
width: barWidth,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(6),
topRight: Radius.circular(6),
),
rodStackItems: [
BarChartRodStackItem(
0,
value1,