flutter_percent_indicator
flutter_percent_indicator copied to clipboard
[MultiSegmentLinearIndicator] Adding a segment causes RangeError
Hi,
Thanks for the latest release of MultiSegmentLinearIndicator!
I'm currently facing an issue with the widget's lifecycle (version 4.2.5).
When I add a SegmentLinearIndicator to the segments list, I get the following error:
RangeError (index): Invalid value: Not in inclusive range.
Performing a hot reload makes the error disappear and correctly displays the segment.
Here's a minimal example to reproduce the issue:
final List<SegmentLinearIndicator> segments = [];
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MultiSegmentLinearIndicator(width: double.infinity, segments: segments),
ElevatedButton(
onPressed: () {
setState(() {
segments.add(
SegmentLinearIndicator(
percent: 0.1,
color: Color((Random().nextDouble() * 0xFFFFFF).toInt()).withAlpha(255),
),
);
});
},
child: Text('Add segment'),
),
],
);
}
Thanks for your help!