Formidable Validator — Formdator is a fully object-oriented package for validating Flutter form fields. Its main benefits, compared to all other similar packages, include:
- Dependency-free package: there is only pure Dart code.
- Object-oriented mindset: validation elements are immutable objects that can be combined in various configurations.
- Classes with short — yet meaningful — names like
Reqfor required fields;ReqEmailfor non-empty, well-formed emails;Lenfor length constraints;Intfor integer-only values; and so on. - Easy-to-compose validators: the command
Trim(Email())produces a validator that trims the entered email before validating it. - Multiple validation at once: you can apply multiple validation rules at once by using the
PairorRulesclasses. - Built-in set of compound validators: e.g. to validate an email and limit its length to a maximum of 50 characters, simply use an instance of
Email.len(50)— write less; do more!
For easier integration with the Flutter form fields, every validator implements the call() method so that any validator object can be called as a function — Callable Classes.
A flexible package provides components that can be selected and grouped in various combinations so that user requirements can be fulfilled.
The code below shows how you can easily group the classes Rules, Req, Len, and Email to create a kind of 'required-email-maximum-50-characters' constraint.
@override Widget build(BuildContext context) { return TextFormField( validator: Rules<String>([ Req(), Len.max(50), Email(), ]), keyboardType: TextInputType.emailAddress, ); }Or — even better — use the compound validator ReqEmail to perform the same task.
@override Widget build(BuildContext context) { return TextFormField( validator: ReqEmail.len(50), keyboardType: TextInputType.emailAddress, ); }The shorter command ReqEmail.len(50) is equivalent to the much longer command Rules<String>([Req(), Len.max(50), Email()]) — write less; do more!
For a complete list of validators with detailed information about each one (constructors, parameters, etc.):
- brazil — validators related to Brazil (BrMobile, BrPhone, Cep, Cnpj, Cpf, etc.).
- core — core validators (Len, Match [text pattern], Pair, Req, Rules, Trim, etc.).
- logic — validation logic and unit testing (Equal, Ok, Nok, ValueBack).
- net — internet (Email, Ipv4, Ipv6, MacAddr, Url, etc.).
- numeric — validators related to numbers or digits (Digit, Hex, Int, Num, etc.).
The demo application provides a fully working example, focused on demonstrating exactly four validators in action — Pair, ReqLen, ReqEmail, and Equal. You can take the code in this demo and experiment with it.
To run the demo application:
git clone https://github.com/dartoos-dev/formdator.git cd formdator/example/ flutter run -d chromeThis should launch the demo application on Chrome in debug mode.
