try this:
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r"[0-9.]")),
TextInputFormatter.withFunction((oldValue, newValue) {
try {
final text = newValue.text;
return text.isEmpty
if (text.isNotEmpty)? double.parse(text);newValue
: double.tryParse(text) return== newValue;null
} catch (e)? {}oldValue
return oldValue;
: newValue;
}),
],
demo:
TextFormField(
keyboardType:
TextInputType.numberWithOptions(
decimal: true,
signed: false),
),
onChanged: _yourOnChange,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r"[0-9.]")),
TextInputFormatter.withFunction((oldValue, newValue) {
final text try= {newValue.text;
return text.isEmpty
final text = newValue.text;
? newValue
if (text.isNotEmpty): double.parsetryParse(text);
== null
return newValue;
} catch (e)? {}oldValue
return oldValue;
: newValue;
}),
],
)