formdator 0.8.0 copy "formdator: ^0.8.0" to clipboard
formdator: ^0.8.0 copied to clipboard

outdated

A formidable collection of Flutter form field validators that can be selected and grouped into various combinations through composition — Decorator Pattern.

formdator #

EO-Color logo

EO principles respected here DevOps By Rultor.com

pub license PDD status

build codecov CodeFactor Grade style: lint Hits-of-Code

Contents #

Overview #

Formidable Validator — Formdator is a fully object-oriented package for validating Flutter form fields. Its key benefits, compared to all other similar packages, include:

  • An object-oriented mindset: the elements for validation are immutable, flexible objects that can be combined in various configurations.
  • Classes with short — yet meaningful — names like Req for a required field; ReqEmail for a non-empty, well-formed email; Len.max for a maximum number of characters; and so on.
  • Easy-to-compose validators: the command Trim(Email()) produces a validator that trims the entered email before validating it.
  • A built-in set of ready-to-use compound validators: if you need to validate an email and limit its length to, say, 50 chars, simply pass an Email.len(50) or ReqEmail.len(50) object as the validation argument.
  • You can apply multiple validation rules at once by using the Pair or Rules classes.

For easier integration with Flutter form fields, each validator implements the call() method so that any validator object can be called like a function — Callable classes.

Getting Started #

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 Rules, Req, Len, and Email validators to create a kind of 'required-max-50-chars-email' 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()]).

List of Validators #

For a complete list of validators with detailed information about each one (constructors, parameters, etc.):

Grouped by Category #

  • brazil — validators related to Brazil (Cep, Cnpj, Cpf, etc).
  • core — core validators (Len, Pair, Req, Rules, Trim, etc).
  • logic — validation logic and unit testing (Equal, Ok, Nok, ValueBack, etc).
  • net — internet (Email, Ipv4, Ipv6, Mac, Url, etc).
  • numeric — validators related to numbers or digits (Digit, Hex, Num, etc).

Demo application #

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 chrome

This should launch the demo application on Chrome in debug mode.

formdator-demo-app

References #

28
likes
0
points
118
downloads

Publisher

verified publisherdartoos.dev

Weekly Downloads

A formidable collection of Flutter form field validators that can be selected and grouped into various combinations through composition — Decorator Pattern.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cpf_cnpj_validator, flutter

More

Packages that depend on formdator