Skip to content

[MultiSegmentLinearIndicator] Adding a segment causes RangeError #230

@ad-angelo

Description

@ad-angelo

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions