NonZeroFormatter class

A lightweight TextInputFormatter that keeps numeric input non-zero.

It rejects a lone 0 and any redundant leading zero (00, 01, 007), so the entered number can never be zero or zero-prefixed. An optional leading minus sign is tolerated (the check runs on the digits after it).

By default allowDecimalZero permits 0. / 0.5 style values while typing, since those are non-zero decimals. Set it to false to reject every value that starts with 0.

TextField(
  keyboardType: TextInputType.number,
  inputFormatters: [
    FilteringTextInputFormatter.digitsOnly,
    NonZeroFormatter(),
  ],
);
Inheritance

Constructors

NonZeroFormatter({bool allowDecimalZero = true})

Properties

allowDecimalZero bool
When true, a leading 0 is allowed only when it is the start of a decimal (0. or 0.5). When false, any leading 0 is rejected.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) TextEditingValue
Called when text is being typed or cut/copy/pasted in the EditableText.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited