Skip to content

NumberInput

A numeric variant of TextInput — accepts digits, an optional leading -, and (when allowDecimal is true) one .. Anything else is silently rejected so the field’s text always parses, and onChanged fires with the parsed num (or null for empty / in-progress edits like "-" or "1.").

See also: Stepper for arrow-key increments.

Learn more: Forms & validation

Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.

NumberInput(
initialValue: 42,
min: 0,
max: 100,
// null while the field is empty or mid-edit ("-", "1.").
onChanged: (value) => setState(() => count = value),
)

Wraps TextInput under the hood — its placeholder, focus, cursor, and Enter-to-submit behavior carry over. There is no Escape callback, so Escape passes on to enclosing widgets. Use this when you’d otherwise pair a TextInput with int.tryParse everywhere.

ParameterTypeDefaultDescription
initialValue:num?—Initial parsed value to seed the field with. null starts empty. More
controller:TextEditingController?—Optional text controller for embedding this field in a larger form.
onChanged:void Function(num? value)?—Called with the parsed value after user or semantic edits. Programmatic controller writes notify controller listeners instead. null is passed when the field is empty or holds an in-progress token like "-" or "1." that doesn’t yet parse to a num.
onSubmit:void Function(num? value)?—Called with the final parsed value when the user presses Enter. Same null semantics as onChanged.
min:num?—Clamps the parsed value (after the user finishes editing) to this lower bound. Per-keystroke values below the bound are still accepted while the user is typing — the clamp applies on submit. Set to enforce a non-negative budget, percentage, etc. More
max:num?—Upper-bound mirror of min. Must be an int when allowDecimal is false.
allowNegative:booltrueWhen false, the field rejects - entirely.
allowDecimal:boolfalseWhen true, the field accepts one . for decimal entry. When false, only integer digits are accepted.
placeholder:String''Forwarded to the inner TextInput verbatim.
placeholderStyle:CellStyleconst CellStyle(dim: true)Style used for placeholder.
style:CellStyleCellStyle.noneEntered-text base styling, plus optional hover, focus, disabled, and invalid state entries from CellStyle.interactive.
cursorStyle:CellStyleconst CellStyle(inverse: true)Style applied to the cursor cell.
semanticLabel:String?—Label exposed through the semantic app graph. More
focusNode:FocusNode?—Focus node used by the underlying text input.
autofocus:boolfalseWhether the field should request focus when mounted.
enabled:booltrueWhether the field accepts focus and user input.
readOnly:boolfalseWhether the field can receive focus but not edit text.
  • initialValue: Used once when the internal controller is created; rebuilds do not reset edits. Supply either this seed or controller. This must be an int when allowDecimal is false.
  • min: Must be an int when allowDecimal is false.
  • semanticLabel: When omitted, placeholder still labels the underlying text field.

NumberInput is defined in packages/fleury/lib/src/catalog/number_input.dart.

Category: Inputs & controls · All widgets