FormattedValueState

@Stable
class FormattedValueState

A hoistable state holder for a FormattedTextField: the value the field holds, whether the characters it currently shows parse, and the gesture that takes a typed edit on demand.

value is two-way: assigning it renders that value through the field's formatter, and a value the field commits - the user pressing Enter, the field losing focus, or commit - is written back into it. The state is the single source of truth; there is no onValueChange.

value and isEditValid are snapshot-observable: reading one inside a composable (or a snapshotFlow collector) subscribes to later commits and to what the user types, so the reader recomposes as the field moves. Gating a form's save button on isEditValid is what that buys.

A state drives at most one field: declaring it on a second one moves it there and leaves the first unbound.

See also

Properties

Link copied to clipboard

Whether the characters the field currently shows parse. It moves with what the user types rather than with what the field commits, so a part-typed edit reports false while value stands where the last commit left it. true while no field renders this state.

Link copied to clipboard
var value: Any?

The value the field renders, typed as the formatter produces it (an Int, a Date, a String, ...). Assigning it re-renders the field's characters from the new value, which replaces characters the user has typed but not committed; a value the field itself commits is written back here.

Functions

Link copied to clipboard

Takes the field's current text as its value, and returns whether it was taken. A commit that lands on a value the field did not hold before moves value onto it, like any other commit.