Skip to content

fix: order in _onChanged of StacSliderState #321

@p1tt

Description

@p1tt

Form data in onChanged of the StacSlider is set after running Stac.onCallFromJson. This leads to old data if form data is directly used in the onChanged action of the slider.

Fix is easy and straight forward in:
packages/stac/lib/src/parsers/widgets/stac_slider/stac_slider_parser.dart

Actual code (line 49 to 58):

  void _onChanged(double value) {
    selectedValue = value;
    if (widget.model.onChanged != null) {
      Stac.onCallFromJson(widget.model.onChanged, context);
    }
    if (widget.model.id != null) {
      widget.formScope?.formData[widget.model.id!] = value;
    }
    setState(() {});
  }

To fix the behaviour just reorder the two if's:

  void _onChanged(double value) {
    selectedValue = value;
    if (widget.model.id != null) {
      widget.formScope?.formData[widget.model.id!] = value;
    }
    if (widget.model.onChanged != null) {
      Stac.onCallFromJson(widget.model.onChanged, context);
    }
    setState(() {});
  }

I can make a pull request if you want, but I think the fix is too easy.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions