form-validator icon indicating copy to clipboard operation
form-validator copied to clipboard

Double can be null but less then some double value in TextFormField.

Open mjarpitanand opened this issue 4 years ago • 1 comments

I have a textformfield in which i want user can leave that i.e not required field but if it fill should be less than some double value. I have keyboard formattor to set to digits only.

mjarpitanand avatar Jan 13 '22 09:01 mjarpitanand

You can provide custom validators using .add method like:

ValidationBuilder(optional: true)
  ..add((value) => (double.tryParse(value) ?? 0.0) < someDoubleValue
    ? null
    : 'Value has to be less than $someDoubleValue');

Callbacks provided to add method is same as validator callbacks for TextFormField which means you return null if validation passes or return error message.

themisir avatar Jan 13 '22 10:01 themisir