min static method
Validator that requires the field's value to be greater than or equal to the provided number.
Validate against a minimum of 5
TextFormField(
keyboardType: TextInputType.numberWithOptions(
decimal: true,
signed: true,
),
decoration: InputDecoration(
labelText: 'Minimum 5',
),
validator: Validators.min(5, 'Value less than 5 not allowed'),
),
Implementation
static FormFieldValidator<String> min(double min, String errorMessage) {
return (value) {
if (value == null) {
value = '';
}
if (value.trim().isEmpty)
return null;
else {
final dValue = _toDouble(value);
if (dValue < min)
return errorMessage;
else
return null;
}
};
}