๐Ÿ“„ 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

  1. โœ… Built-in Validators (Email, Phone, Password Strength, URL, etc.)
  2. ๐Ÿ”„ Dynamic Validation based on user input
  3. ๐Ÿ” AI-Powered Validation for text analysis and smart suggestions
  4. ๐ŸŒ Multi-language Support (i18n)
  5. ๐Ÿ“ฒ 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add some feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. 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!