fl_chart
fl_chart copied to clipboard
Tooltip on Barchart: index out of range
[Short description] I get an index out of range when switching between different BarCharts with different length of BarChartGroupData when tooltip is always showing.
I have lots of BarCharts with multiple BarChartGroupData each. I switch between different BarCharts with a slider. The number of BarChartGroupData for each Barchart differs! The tooltip is always showing by setting "showingTooltipIndicators: [0]".
When I switch between a Barchart with 10 BarChartGroupData to a Barchart with 11 BarChartGroupData everything works fine! However, when I switch from 11 to 10, the exception occurs.
Important: I am only able to reproduce this bug when the tooltip is always showing with "showingTooltipIndicators: [0]".
I use most recent version of flutter and fl_chart
EDIT: here is code to reproduce:
class MyWidget2 extends StatelessWidget {
final int max;
const MyWidget2(this.max, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: 100,
child: BarChart(
BarChartData(
barGroups: [
for(int i=0; i<max; i++)
BarChartGroupData(
x: i,
showingTooltipIndicators: [0],
barRods: [
BarChartRodData(
y: 1,
),
],
),
],
),
),
);
}
}
If you switch between different max values, for example MyWidget2(11) to MyWidget2(10), an Index out of range exception occurs.
The problem is caused by the animation when changing. Ideally, the tooltips should be deactivated in the package during animation. Alternatively, the chart can be used in a stateful widget and the permanent tooltips can be activated via a PostFrameCallback.
The simplest workaround is to disable the animation.
BarCart(
...
swapAnimationDuration: Duration.zero,
)
Hi guys. Can you please check it with the latest version?
If it still happens, please give me a reproducible code.
If it still happens, please give me a reproducible code.
I updated my pubspec but get the same error with the code I have attached in the initial post.
Specifying unique key on BarChart() fixes this
BarChart(
key: UniqueKey(),
...
),