Search packages, repositories and app categories

Package detailsv2.0.0

the_validator

A simple & easy validation package for flutter that can be used to validate form fields and strings & values

AndroidiOSWebmacOSWindowsLinux
30-day downloads
183
Likes
25
Pub points
130

Install package

flutter pub add the_validator

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The Validator is a lightweight Flutter package designed for simple and efficient form field, string, and value validation. It provides a clean, intuitive API to validate inputs such as emails, passwords, and custom conditions. Ideal for developers seeking quick integration without complex setup, it supports multiple platforms including Android, iOS, Web, macOS, Windows, and Linux. The package enhances user experience by enabling real-time feedback during form input. Its minimalistic approach makes it easy to adopt in any Flutter project requiring basic or advanced validation logic.

Use cases

  • Form input validation
  • Email and password checks
  • Custom validation rules
  • Real-time user feedback
  • Data integrity in user forms
  • Cross-platform validation

Key features

  • Simple API
  • Supports multiple validation types
  • Real-time validation
  • Cross-platform compatibility
  • Extensible validation rules
  • Lightweight and fast

Suitable for

  • Beginner Flutter developers
  • Projects needing quick validation
  • Mobile and web applications
  • Form-heavy apps
  • Apps with strict data entry requirements
  • Developers preferring minimal dependencies

Considerations

  • Limited to basic validation needs
  • No built-in internationalization
  • Requires manual error message handling
  • Not ideal for highly complex validation workflows
  • Depends on external GitHub repository
  • Minimal documentation beyond basic examples

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

The Validator

A simple & lightweight form and data validation package for flutter

How to use

The Validator can be used directly on a TextFormField validator parameter TextFormField(validator: FieldValidator.email())

The Validator can also be used as a stand alone validator Validatror.isPassword('SecretPass', shouldContainCapitalLetter: true)

Sample Usage (FieldValidator)

TextFormField( 
    controller: _emailController,
    validator: FieldValidator.email(),
    decoration: InputDecoration(labelText: "Email"),
    ),
                
 TextFormField( 
    controller: _passwordController,
        validator: FieldValidator.password(
        minLength: 8,
        shouldContainNumber: true,
        shouldContainCapitalLetter: true,
        shouldContainSmallLetter: true,
        shouldContainSpecialChars: true,
        errorMessage: "Password must match the required format",
        isNumberNotPresent: () { return "Password must contain number"; },
        isSpecialCharsNotPresent: () { return "Password must contain special characters"; },
        isCapitalLetterNotPresent: () { return "Password must contain capital letters"; }
        ),
        decoration: InputDecoration(labelText: "Email"),
    ),

To validate confirm password field

  // To validate confirm password field
  TextFormField(
      controller: _confirmPasswordController,
      obscureText: true,
      validator: FieldValidator.equalTo(_passwordController, message: "Password Mismatch"),
      decoration: InputDecoration(labelText: "Confirm Password"),
  )

Then make a call to formState .validate() to perform the validations on the textfields


RaisedButton(
  onPressed: () {
    // validate() inputed data
    if (_formKey.currentState.validate()) {

          _scaffoldKey.currentState
          .showSnackBar(SnackBar(content: Text("Yay! we got it right!")));
                      
    }
  },
  child: Text("Submit"),                  
)

Sample Usage 2 (Validator)

var password = 'Secret'
var confirmPassword = 'secret'
if (Validator.isPassword(password, shouldContainCapitalLetter: true)) {
  if (Validator.isEqualTo(password, confirmPassword)) {
    print("Go ahead & grant access")
  } else {
    print("Password mis match")
  }
}

Error messages

By default The Validator will give you a nice default error based on the the type of validation you specify for field or an input. But you can also override the default message

Default Error Messages

FieldValidator.alphaNumeric() will output Field must contain both alphabets and numbers

User Defined Error Message

FieldValidator.alphaNumeric(message: 'Your username must contain both numbers & alphabets')

Categories

Source repository

Projects using this package

No data available yet.