form_validators 0.1.0

Form Validator #

A library to validate form fields for Flutter framework

This library only for flutter framework.

to use the JS-based please see Web form validators (Under development yet)

Validators #

Here is a list of the validators currently available.

Contains(String seed, [String message])check if the string contains the seed.
Equals(String seed, [String message])check if the field value equal to a certain string
Required([String message])Mark the field is required.
MaxLength(int limit, [String message])Set the maximum amount of character.
MinLength(int limit, [String message])Set the minimum amount of character.
Between(String message, {int max, int min})Limit the field digits to be between limited range

it use MaxLength and MinLength validators.

the message argument is required here
Composs(String message, List validators)Composs multiple validator into one singular validator.

the message argument is required here
Email([String message, String regexp])Indicate that the field should be an email

It uses a common regexp to validate the string, but you can use your own

the regexp is r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+"]
Pattern(String regexp, [String message])check if the field value matches the pattern.

Usage #

Just use the validate function to execute the list of predefined validators

    validator: validate([
	    Required('This field is required'),
	    Email('Please enter the email correctly'),

and the validator function will be executed using either the global key of the Form widget or the Form Field, click Here for more information about flutter validation.

please note that the validators functions will be executed in the same order that was defined

the validators are simple functions that returns true when the value is not as supposed so you can build your validators the works the same as the predefined ones

 class CustomValidator implements IValidator {
	 final String message = 'Message to be used as error message';
	 call(String value) {
		 return ("if meets my condition") ? false : true;

also, you can always see the source code to learn more.

The last thing that you can use a 3rd lib to facilitate the process, you can see this one, here's one of it's function isDate() that validates if the string is date, because it's a function that returns boolean we can use it with our interface to form a validator function, like this:

 class IsDate implements IValidator {
	 final String message = 'Message to be used as error message';
	 call(String value) {
		 return isDate(value);
    key: myFormKey,
    validator: validate([
	    IsDate('Please enter correct date')

Contributing #

Don't hesitate to open issues and make pull request to help improve this plugin.

Maintainers #

ezzabuzaid - (author) -

Made with love #

This lib inspired by #

[0.0.3] - 2019-08-01.

  • Initial release.

[0.0.4] - 2019-08-14.

  • Update docs

[0.1.0] - 2019-08-14.

  • Stable release

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  form_validators: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:form_validators/form_validators.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 18, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and form_validators.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies