Skip to content

Commit

Permalink
fixed: CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeYslaoker committed Dec 20, 2024
1 parent fe0acc5 commit 9c20806
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## 1.0.0+1
- Updated CHANGELOG.

## 1.0.0
- Initial release.
160 changes: 150 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<FancyInput> 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<SimpleFormScreen> createState() => _SimpleFormScreenState();
}
class _SimpleFormScreenState extends State<SimpleFormScreen> {
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.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 9c20806

Please sign in to comment.