flutter_percent_indicator icon indicating copy to clipboard operation
flutter_percent_indicator copied to clipboard

[MultiSegmentLinearIndicator] Adding a segment causes RangeError

Open ad-angelo opened this issue 4 months ago • 0 comments

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!

ad-angelo avatar Aug 03 '25 15:08 ad-angelo