You can add a deny
constructor at the beginning and replace ,
with .
:
TextField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.deny(',', replacementString: '.')
FilteringTextInputFormatter.allow(RegExp(r'(^\d*\.?\d{0,2})')),
],
)
If you need to keep the system separator by https://pub.dev/packages/intl, you can pre-define it and then use it in RegExp
import 'dart:ui' as ui;
import 'package:intl/number_symbols_data.dart' show numberFormatSymbols;
...
String locale = '${ui.window.locale.languageCode}_${ui.window.locale.countryCode}';
if (!numberFormatSymbols.keys.contains(locale))
locale = ui.window.locale.languageCode;
final separator = numberFormatSymbols[locale]?.DECIMAL_SEP ?? '.';
...
TextField(
keyboardType: TextInputType.numberWithOptions(decimal: true),
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp('(^\\d*$separator?\\d{0,2})')),
],
)