๐ Smart Form Validator - Flutter Package Documentation
๐ Introduction
Smart Form Validator is a comprehensive Flutter package that simplifies form validation with a wide range of built-in and customizable validators. It offers real-time feedback, dynamic conditions, and AI-powered text validation, enhancing the user experience for complex form structures.
๐ฆ Installation
Add the package to your Flutter project by including it in your pubspec.yaml file:
dependencies:
smart_form_validator:
path: ../ # For local development, or replace with the published version
Install the dependencies:
flutter pub get
๐๏ธ Folder Structure
smart_form_validator/
โโโ lib/
โ โโโ smart_form_validator.dart # Main export file
โ โโโ validators/ # Validator classes
โ โ โโโ required_validator.dart
โ โ โโโ email_validator.dart
โ โ โโโ phone_validator.dart
โ โ โโโ password_strength_validator.dart
โ โ โโโ ... (other validators)
โ โโโ widgets/
โ โ โโโ smart_form_field.dart # Custom form field with real-time feedback
โโโ example/ # Example app
โโโ test/ # Unit tests
โจ Features
- โ Built-in Validators (Email, Phone, Password Strength, URL, etc.)
- ๐ Dynamic Validation based on user input
- ๐ AI-Powered Validation for text analysis and smart suggestions
- ๐ Multi-language Support (i18n)
- ๐ฒ Real-time Validation Feedback
๐ ๏ธ Usage
1. Import the Package
import 'package:smart_form_validator/smart_form_validator.dart';
2. Basic Validators
Required Field Validator
SmartFormField(
label: "Username",
controller: _usernameController,
validators: [
RequiredValidator(errorMessage: "Username is required."),
],
)
Email Validator
SmartFormField(
label: "Email",
controller: _emailController,
validators: [
RequiredValidator(errorMessage: "Email is required."),
EmailValidator(errorMessage: "Please enter a valid email address."),
],
)
Phone Number Validator
SmartFormField(
label: "Phone Number",
controller: _phoneController,
validators: [
RequiredValidator(errorMessage: "Phone number is required."),
PhoneValidator(errorMessage: "Invalid phone number."),
],
)
3. Advanced Validators
Password Strength Validator
SmartFormField(
label: "Password",
controller: _passwordController,
obscureText: true,
validators: [
RequiredValidator(errorMessage: "Password is required."),
PasswordStrengthValidator(errorMessage: "Password must include uppercase, lowercase, number, and symbol."),
],
)
URL Validator
SmartFormField(
label: "Website",
controller: _websiteController,
validators: [
RequiredValidator(errorMessage: "Website URL is required."),
UrlValidator(errorMessage: "Please enter a valid URL."),
],
)
Credit Card Validator
SmartFormField(
label: "Credit Card Number",
controller: _creditCardController,
validators: [
RequiredValidator(errorMessage: "Credit card number is required."),
CreditCardValidator(errorMessage: "Invalid credit card number."),
],
)
4. AI-Powered Validation
Smart Text Validator
SmartFormField(
label: "Feedback",
controller: _feedbackController,
validators: [
RequiredValidator(errorMessage: "Feedback cannot be empty."),
AdvancedSmartTextValidator(),
],
)
๐ AI Validator Checks:
- Detects spelling mistakes
- Identifies negative sentiment
- Avoids repetitive characters
- Detects contradictory words
5. Dynamic Validation
SmartFormField(
label: "Tax ID",
controller: _taxIdController,
validators: [
DynamicValidator(
condition: () => _userType == 'Company',
validator: RequiredValidator(errorMessage: "Tax ID is required for companies."),
),
],
)
๐งช Testing
Run unit tests to ensure validators work as expected:
flutter test
Example Test:
import 'package:flutter_test/flutter_test.dart';
import 'package:smart_form_validator/smart_form_validator.dart';
void main() {
test('Phone Validator Test', () {
final validator = PhoneValidator();
expect(validator.validate('+1234567890'), null); // Valid
expect(validator.validate('12345'), "Please enter a valid phone number."); // Invalid
});
}
๐ All Available Validators
| Validator | Description |
|---|---|
RequiredValidator |
Checks if the field is not empty |
EmailValidator |
Validates email format |
PhoneValidator |
Validates international phone numbers |
PasswordStrengthValidator |
Ensures strong passwords |
UrlValidator |
Validates URLs |
CreditCardValidator |
Validates credit card numbers |
DateValidator |
Validates date formats |
NumericValidator |
Checks if the input is numeric |
RangeValidator |
Checks if value falls within a range |
RegexValidator |
Custom regular expression validation |
AdvancedSmartTextValidator |
AI-based smart text analysis |
DynamicValidator |
Conditional validation |
๐ Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a pull request
๐ง Contact
For feature requests or issues, please open a ticket on GitHub or reach out via email at furkankalender46@gmail.com.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Thank You for Using Smart Form Validator!
Ready to build smarter forms with dynamic, real-time, and AI-powered validation!
Libraries
- smart_form_validator
- text_form_field/smart_form_field
- validators/advenced_smart_validator
- validators/credit_card_validator
- validators/date_validator
- validators/dynamic_validator
- validators/email_validator
- validators/index
- validators/min_length_validator
- validators/multi_validator
- validators/numeric_validator
- validators/password_strength_validator
- validators/phone_validator
- validators/range_validator
- validators/regex_validator
- validators/required_validator
- validators/smart_form_validator_service.dart
- validators/url_validator