From 9c20806a680c6b98ac8f5e518d5356ff6ad26f9c Mon Sep 17 00:00:00 2001 From: Felipe Yslaoker Date: Thu, 19 Dec 2024 22:18:25 -0300 Subject: [PATCH] fixed: CHANGELOG --- CHANGELOG.md | 3 + README.md | 160 +++++++++++++++++++++++++++++++++++++++++++++++---- pubspec.yaml | 2 +- 3 files changed, 154 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3141da..1282d7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,5 @@ +## 1.0.0+1 +- Updated CHANGELOG. + ## 1.0.0 - Initial release. diff --git a/README.md b/README.md index 4f70aad..3428289 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,166 @@ A flexible and easy-to-use form management solution for Flutter. The `fancy_form ## Features -- **Custom Validation**: Use predefined validators like `notEmpty`, `minLength`, `validEmail`, and more. +- **Built-in Validators**: Use predefined validators like `notEmpty`, `minLength`, `validEmail`, etc. - **Input Masking**: Supports input masks for fields like phone numbers. -- **Easy Integration**: Manage forms with the `FancyManager` and create dynamic forms easily. -- **State Management**: Automatic form validation and state management with `FancyManager`. -- **Custom Input Fields**: Define custom form inputs with validation rules and masks. +- **Easy Integration**: Manage forms with `FancyManager`. +- **State Management**: Automatic validation and form state management. +- **Custom Input Fields**: Create your own form inputs with rules and masks. ## Installation -To use this package, add it to your `pubspec.yaml` file: +Add the package to your `pubspec.yaml`: ```yaml dependencies: fancy_form: ^1.0.0 ``` -Then, run `flutter pub get` to install the dependencies. +Run `flutter pub get` to install. ## Usage -1. Create a Form Manager -To manage your form, create a class that extends FancyManager. This class will handle the form inputs, validation rules, and controllers. +### 1. Create a Form Manager +Define a form manager by extending `FancyManager`. It handles the inputs and validation. -dart -Copiar código +```dart +import 'package:fancy_form/fancy_form.dart'; +import 'package:flutter/services.dart'; + +class GreatForm extends FancyManager { + @override + List inputs = [ + FancyInput( + id: 'name', + rules: (value) => [ + FancyValidator.notEmpty(value), + () { + if (value.trim().split(' ').length < 2) { + return 'Please enter your full name.'; + } + return null; + }, + ], + ), + FancyInput( + id: 'phoneNumber', + mask: '(##) #####-####', + rules: (value) => [FancyValidator.notEmpty(value)], + keyboardType: TextInputType.phone, + ), + ]; +} +``` +### 2. Create the Form UI +Use `FancyForm` and `FancyFormField` to display and manage the form inputs. + +```dart +import 'package:fancy_form/fancy_form.dart'; +import 'package:flutter/material.dart'; + +class SimpleFormScreen extends StatefulWidget { + const SimpleFormScreen({super.key}); + + @override + State createState() => _SimpleFormScreenState(); +} + +class _SimpleFormScreenState extends State { + final greatForm = GreatForm(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text('Simple Form')), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: FancyForm( + fancyManager: greatForm, + child: ListView( + children: [ + FancyFormField( + fancyKey: FancyKey(id: 'name', formManager: greatForm), + decoration: InputDecoration(labelText: 'Full Name'), + ), + FancyFormField( + fancyKey: FancyKey(id: 'phoneNumber', formManager: greatForm), + decoration: InputDecoration(labelText: 'Phone Number'), + ), + FilledButton( + onPressed: () { + if (greatForm.validate()) { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Form validated successfully'), + ), + ); + } + }, + child: Text('Submit'), + ), + ], + ), + ), + ), + ); + } +} +``` + +### 3. Form Validation +To validate the form: + +```dart +bool isValid = greatForm.validate(); +if (isValid) { + // Form is valid, proceed with submission +} else { + // Handle invalid form +} +``` + +### 4. Accessing Input Values +You can retrieve the value of any input field using `getText(id)` or by using the controller: + +```dart +String name = greatForm.getText('name'); +``` + +### 5. Disposing of Form Resources +Dispose of the form when not in use: + +```dart +greatForm.dispose(); +``` + +## Custom Validators +In addition to built-in validators like `notEmpty`, `minLength`, `validEmail`, and `validCPF`, you can create custom validation functions within the rules for each `FancyInput`. Simply define a function that checks a condition and returns an error message if validation fails. + +### Example: +Custom validation to ensure the input contains at least two words: + +```dart +FancyInput( + id: 'name', + rules: (value) => [ + FancyValidator.notEmpty(value), + () { + if (value.trim().split(' ').length < 2) { + return 'Please enter your full name.'; + } + return null; + }, + ], +) +``` + +## Contributions + +Contributions are welcome! If you want to contribute to this project, please follow these steps: + +1. **Fork this repository.** +2. **Create a new branch for your modification.** +3. **Make your changes and submit a pull request.** + +## License +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 58dd837..61963f0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fancy_form description: A flexible and easy-to-use form management solution for Flutter. -version: 1.0.0 +version: 1.0.0+1 repository: https://github.com/MusilyApp/dart_ytmusic_api.git environment: