form_validations_kit

Rule-based โ€ข Testable โ€ข No UI dependency โ€ข Flutter


๐Ÿš€ Overview

form_validations_kit is a lightweight, reusable, and production-ready
form validation engine for Flutter.

It helps you keep validation logic:

  • clean
  • reusable
  • testable
  • independent from UI

No more duplicated validators across screens.


โœจ Features

  • โœ… Rule-based validation engine
  • ๐Ÿ“ง Email validation
  • ๐Ÿ” Password strength rules
  • ๐Ÿ” Confirm password matching
  • ๐Ÿ“ž Phone & numeric validation
  • โšก Fast-exit validation (first error only)
  • ๐Ÿงช Pure Dart, easy to test
  • ๐ŸŽฏ No UI dependency

๐Ÿ“ฑ Platform Support

Platform Supported
Android โœ…
iOS โœ…
Web โœ…
Windows โœ…
macOS โœ…
Linux โœ…

๐ŸŽฌ Example App


๐Ÿ“ฆ Installation

Add this to your pubspec.yaml:

dependencies:
  form_validations_kit: ^0.0.5

Then run:

  flutter pub get


## Usage

Designed to work seamlessly with Flutter Form and TextFormField.

### Required Field

Ensures the field is not empty.

```dart
TextFormField(
  validator: (value) => EasyFormValidator.validate(
    value,
    rules: [Rules.required()],
  ),
);

### Email Validation

Ensures the field is not empty.

```dart
TextFormField(
  keyboardType: TextInputType.emailAddress,
  validator: (value) => EasyFormValidator.validate(
    value,
    rules: [
      Rules.required(),
      EmailRules.email(),
    ],
  ),
);

### Password Validation

Ensures the field is not empty.

```dart
TextFormField(
  obscureText: true,
  validator: (value) => EasyFormValidator.validate(
    value,
    rules: [
      PasswordRules.minLength(8),
      PasswordRules.hasUppercase(),
      PasswordRules.hasNumber(),
      PasswordRules.hasSpecialChar(),
    ],
  ),
);

### Confirm Password Validation

Ensures the field is not empty.

```dart
TextFormField(
  obscureText: true,
  validator: (value) => EasyFormValidator.validate(
    value,
    rules: [
      Rules.required(),
      Rules.match(passwordController.text),
    ],
  ),
);


### Phone Number Validation

Ensures the field is not empty.

```dart
TextFormField(
  keyboardType: TextInputType.phone,
  validator: (value) => EasyFormValidator.validate(
    value,
    rules: [
      Rules.required(),
      NumberRules.phone(),
    ],
  ),
);

### Validate an Entire Form

Ensures the field is not empty.

```dart
final _formKey = GlobalKey<FormState>();

Form(
  key: _formKey,
  child: Column(
    children: [
      // form fields
      ElevatedButton(
        onPressed: () {
          if (_formKey.currentState!.validate()) {
            print('Form is valid ๐ŸŽ‰');
          }
        },
        child: const Text('Submit'),
      ),
    ],
  ),
);