A simple to use TextEditingController for handling money values.
dependencies:
money_field: ^1.0.0
flutter packages get
import 'package:money_field/money_field.dart';
final _moneyFieldController = MoneyFieldController();
...
TextFormField(
controller: _moneyFieldController,
keyboardType: TextInputType.number,
),
final _moneyFieldController = MoneyFieldController(
decimalSeparator = '.',
thousandsSeparator = ',',
invalidFormatError = 'Invalid input format',
invalidLengthError = 'Length must be less than or equal to 9',
maxDigitsBeforeDecimal = 9
);
final _moneyFieldController = MoneyFieldController();
var doubleValue = _moneyFieldController.doubleValue();
final _moneyFieldController = MoneyFieldController();
TextFormField(
controller: _moneyFieldController,
keyboardType: TextInputType.number,
validator: (_) {
return _moneyFieldController.moneyFieldValidator();
},
),
If you'd just like to check if the input is valid, without using the validator, you can:
final _moneyFieldController = MoneyFieldController();
bool isFormatValid = _moneyFieldController.isFormatValid();
bool isLengthValid = _moneyFieldController.isLengthValid();
// Checks if format and length are valid
bool isValid = _moneyFieldController.isInputValid();
If you encounter any issues, feel free to post them on the GitHub page.