callor

EO-Color logo

EO principles respected here DevOps By Rultor.com

pub license style: lint PDD status build codecov Hits-of-Code

Callable Validator - Callor is a fully object-oriented package for validating form fields before they get processed. Its key benefits, compared to all other similar packages, include:

  • Object-oriented mindset: no static functions; only trustworthy immutable objects.
  • Easy-to-compose validators. E.g., for a "trimmed-required-email": Trim(ReqEmail(blank:'required field', mal:'malformed email')).
  • You can compose your own multi-rule validation logic - via the Rules class.
  • Classes with short - yet meaningful - names. E.g: Req for a required (non-blank) field; ReqEmail for a non-blank, well-formed email; MinLen for a minimum number of characters.
  • No complex class hierarchy: the validator classes just implement the Dart's built-in call() method.

For easier integration with the fields of a Flutter form, each validator implements the call() method; therefore, any validator can be treated as if it were an ordinary function.

Classes that implement the call() method are collectively known as Callable classes; that's the reason for the name "Callor": Callable Validator :-).

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 Trim and Email to form a trimmed-email field:

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      onSaved: _onSaved,
      validator: Trim(Email(mal: 'malformed email.')),
      keyboardType: TextInputType.emailAddress,
    );
  }

Demo application

The demo application provides a fully working example, focused on demonstrating exactly four validators in action - Rules, Req, Email, 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/callor.git
cd callor/example/
flutter run -d chrome

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

callor_demo_app

Libraries

brazil
Brazil-related validators.
callor
Callor - Callable Validator. According to the Flutter form standards, a validator must return the null value to indicate that an input is valid. On the other hand, to indicate a valid input, a validator must return a message, which in turn will be displayed to the user by the field with wrong data.
core
The package's core validators.
logic
Validation logic and unit testing.
net
Internet related validators.