Skip to content

fix: notify a button or key step once, without re-entering the listener - #110

Open
palmoni5 wants to merge 2 commits into
ubuntu-flutter-community:mainfrom
palmoni5:fix/single-change-per-step
Open

palmoni5 wants to merge 2 commits into
ubuntu-flutter-community:mainfrom
palmoni5:fix/single-change-per-step

Conversation

@palmoni5

Copy link
Copy Markdown

Stacked on #109 (contains its commit); review only the last commit.

Problem

A step relied on the controller listener to update the value and call onChanged. That listener ran inside setState, called canChange a second time for the same value and triggered a second setState.

Fix

Suppress the listener while the widget writes its own text, update the value and call onChanged explicitly, shift the selection by the old/new text and clamp it, and clear the stale IME composing range.

Behavior

+/- buttons and arrow/page keys call onChanged exactly once, explicitly, and canChange once.

Tests

button step sends one numeric change callback (regression guard).

CI on main currently fails in the Android example build and the publish dry-run; it goes green with #102.

setValue clamped the requested value and then formatted it with the
configured number of decimals. A NaN or infinite value was written into
the text field, and rounding could push a clamped value past a
fractional bound (max: 0.29 with decimals: 1 accepted 0.3).

Ignore non-finite values, round before validating, and drop a step whose
rounded value falls outside [min, max]. onSubmitted now receives the
already-rounded value.
A +/-, arrow or page step wrote the new text into the controller and
relied on the controller listener to update the value and call
onChanged. That listener ran inside setValue's setState, called
canChange a second time for the same value and triggered a second
setState.

Suppress the listener while the widget writes its own text, update the
value directly and call onChanged explicitly, once per step.
_updateController now shifts the selection by the oldValue it is given
(instead of the current value, which didUpdateWidget had already
replaced), clamps it to the new text, and clears any IME composing range
that referred to the old text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant