form_validations_kit 0.0.6
form_validations_kit: ^0.0.6 copied to clipboard
A simple, reusable, and production-ready form validation package for Flutter.
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.6
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'),
),
],
),
);