RT Form Validator

rt_formvalidator is a Flutter package that provides real-time form validation using the RealTimeTextEditingController. This package allows you to add instant feedback on form field inputs, offering customizable validation logic, error handling, and visual indicators.

Features

  • Real-Time Validation: Validate form fields as the user types.
  • Customizable Validators: Define your own validation logic for each form field.
  • Visual Feedback: Show success, error, and idle states with customizable icons and text styles.
  • Form-Wide Validation: Easily check if the entire form is valid.

Installation

Add rt_formvalidator to your pubspec.yaml:

dependencies:
  rt_formvalidator: ^0.1.0

Then run 'flutter pub get' to install the package.

Usage
Basic Example
Here's how you can use rt_formvalidator in your Flutter application:

import 'package:flutter/material.dart';
import 'package:rt_formvalidator/rt_formvalidator.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('RT Form Validator Example')),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: MyForm(),
        ),
      ),
    );
  }
}

class MyForm extends StatelessWidget {
  final RTFormController formController = RTFormController();
  final TextEditingController firstController = TextEditingController();
  final TextEditingController secondController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return RTFormValidator(
      rtFormController: formController,
      child: Column(
        children: [
          RTTextField(
            controller: firstController,
            validator: (value) {
              if (value == "") {
                return "O valor não pode ficar vazio.";
              }
              if (value.length < 5) {
                return "O valor deve conter pelo menos 5 caracteres.";
              }
              return null;
            },
            //this is where the thing changes!!!!
            //the native FlutterEditingController when we use validadeOnUserInteraction
            //validates the whole form
            //this package only validades only the Field itself
            validateOnUserInteraction: true,
            decoration: const InputDecoration(
              border: OutlineInputBorder(),
              errorStyle: TextStyle(),
            ),
            customErrorTextStyle: CustomErrorTextStyle(
              textOverflow: TextOverflow.ellipsis,
              maxLines: 500,
              style: const TextStyle(
                color: Colors.red,
              ),
            ),
            validationPrefixIcons: PrefixValidationIcons(
              iddleIcon: const Icon(Icons.person),
              errorIcon: const Icon(Icons.person, color: Colors.red),
              successIcon: const Icon(Icons.person, color: Colors.green),
            ),
          ),
          RTTextField(
            controller: secondController,
            validator: (value) {
              if (value == "") {
                return "O valor não pode ficar vazio.";
              }
              if (value.length < 5) {
                return "O valor deve conter pelo menos 5 caracteres.";
              }
              return null;
            },
            validateOnUserInteraction: true,
            decoration: const InputDecoration(
              border: OutlineInputBorder(),
            ),
            customErrorTextStyle: CustomErrorTextStyle(
              maxLines: 2,
              style: const TextStyle(color: Colors.blue),
            ),
            validationPrefixIcons: PrefixValidationIcons(
              iddleIcon: const Icon(Icons.person),
              errorIcon: const Icon(Icons.person, color: Colors.red),
              successIcon: const Icon(Icons.person, color: Colors.green),
            ),
          ),
          ElevatedButton(
            onPressed: () {
              bool isFormValid = formController.isFormValid();
              if (isFormValid) {
                ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text("The form is valid")));
              }
            },
            child: const Text("Validate"),
          ),
        ],
      ),
    );
  }
}

Customizing Validation Icons and Styles
You can customize the icons and error text styles for each RTTextField:

RTTextField(
  controller: yourController,
  validator: yourValidator,
  validateOnUserInteraction: true,
  customErrorTextStyle: CustomErrorTextStyle(
    maxLines: 2,
    style: TextStyle(color: Colors.blue),
  ),
  validationPrefixIcons: PrefixValidationIcons(
    iddleIcon: Icon(Icons.person),
    errorIcon: Icon(Icons.person, color: Colors.red),
    successIcon: Icon(Icons.person, color: Colors.green),
  ),
),


Checking Form Validity
You can check if the entire form is valid using the RTFormController:

ElevatedButton(
  onPressed: () {
    bool isFormValid = formController.isFormValid();
    if (isFormValid) {
      // Perform the desired action
    }
  },
  child: Text("Validate"),
),

Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License
This project is licensed under the MIT License - see the LICENSE file for details.

### Steps to Customize:

1. **Installation Section:** Ensure the version of `rt_formvalidator` is correct.
2. **Basic Example:** Adapt the code example to fit the most common use case for your package.
3. **Customizing Section:** You can add more examples or details about customization if needed.
4. **Contributing and License:** Customize these sections according to your preferences and any existing guidelines you have.

Feel free to add more sections or modify this template to better describe the features and usage of your package.