Skip to content

Commit 9c20806

Browse files
fixed: CHANGELOG
1 parent fe0acc5 commit 9c20806

File tree

3 files changed

+154
-11
lines changed

3 files changed

+154
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
## 1.0.0+1
2+
- Updated CHANGELOG.
3+
14
## 1.0.0
25
- Initial release.

README.md

+150-10
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,166 @@ A flexible and easy-to-use form management solution for Flutter. The `fancy_form
44

55
## Features
66

7-
- **Custom Validation**: Use predefined validators like `notEmpty`, `minLength`, `validEmail`, and more.
7+
- **Built-in Validators**: Use predefined validators like `notEmpty`, `minLength`, `validEmail`, etc.
88
- **Input Masking**: Supports input masks for fields like phone numbers.
9-
- **Easy Integration**: Manage forms with the `FancyManager` and create dynamic forms easily.
10-
- **State Management**: Automatic form validation and state management with `FancyManager`.
11-
- **Custom Input Fields**: Define custom form inputs with validation rules and masks.
9+
- **Easy Integration**: Manage forms with `FancyManager`.
10+
- **State Management**: Automatic validation and form state management.
11+
- **Custom Input Fields**: Create your own form inputs with rules and masks.
1212

1313
## Installation
1414

15-
To use this package, add it to your `pubspec.yaml` file:
15+
Add the package to your `pubspec.yaml`:
1616

1717
```yaml
1818
dependencies:
1919
fancy_form: ^1.0.0
2020
```
2121
22-
Then, run `flutter pub get` to install the dependencies.
22+
Run `flutter pub get` to install.
2323

2424
## Usage
25-
1. Create a Form Manager
26-
To manage your form, create a class that extends FancyManager. This class will handle the form inputs, validation rules, and controllers.
25+
### 1. Create a Form Manager
26+
Define a form manager by extending `FancyManager`. It handles the inputs and validation.
2727

28-
dart
29-
Copiar código
28+
```dart
29+
import 'package:fancy_form/fancy_form.dart';
30+
import 'package:flutter/services.dart';
31+
32+
class GreatForm extends FancyManager {
33+
@override
34+
List<FancyInput> inputs = [
35+
FancyInput(
36+
id: 'name',
37+
rules: (value) => [
38+
FancyValidator.notEmpty(value),
39+
() {
40+
if (value.trim().split(' ').length < 2) {
41+
return 'Please enter your full name.';
42+
}
43+
return null;
44+
},
45+
],
46+
),
47+
FancyInput(
48+
id: 'phoneNumber',
49+
mask: '(##) #####-####',
50+
rules: (value) => [FancyValidator.notEmpty(value)],
51+
keyboardType: TextInputType.phone,
52+
),
53+
];
54+
}
55+
```
56+
### 2. Create the Form UI
57+
Use `FancyForm` and `FancyFormField` to display and manage the form inputs.
58+
59+
```dart
60+
import 'package:fancy_form/fancy_form.dart';
61+
import 'package:flutter/material.dart';
62+
63+
class SimpleFormScreen extends StatefulWidget {
64+
const SimpleFormScreen({super.key});
65+
66+
@override
67+
State<SimpleFormScreen> createState() => _SimpleFormScreenState();
68+
}
69+
70+
class _SimpleFormScreenState extends State<SimpleFormScreen> {
71+
final greatForm = GreatForm();
72+
73+
@override
74+
Widget build(BuildContext context) {
75+
return Scaffold(
76+
appBar: AppBar(title: Text('Simple Form')),
77+
body: Padding(
78+
padding: const EdgeInsets.all(16.0),
79+
child: FancyForm(
80+
fancyManager: greatForm,
81+
child: ListView(
82+
children: [
83+
FancyFormField(
84+
fancyKey: FancyKey(id: 'name', formManager: greatForm),
85+
decoration: InputDecoration(labelText: 'Full Name'),
86+
),
87+
FancyFormField(
88+
fancyKey: FancyKey(id: 'phoneNumber', formManager: greatForm),
89+
decoration: InputDecoration(labelText: 'Phone Number'),
90+
),
91+
FilledButton(
92+
onPressed: () {
93+
if (greatForm.validate()) {
94+
showDialog(
95+
context: context,
96+
builder: (context) => AlertDialog(
97+
title: Text('Form validated successfully'),
98+
),
99+
);
100+
}
101+
},
102+
child: Text('Submit'),
103+
),
104+
],
105+
),
106+
),
107+
),
108+
);
109+
}
110+
}
111+
```
112+
113+
### 3. Form Validation
114+
To validate the form:
115+
116+
```dart
117+
bool isValid = greatForm.validate();
118+
if (isValid) {
119+
// Form is valid, proceed with submission
120+
} else {
121+
// Handle invalid form
122+
}
123+
```
124+
125+
### 4. Accessing Input Values
126+
You can retrieve the value of any input field using `getText(id)` or by using the controller:
127+
128+
```dart
129+
String name = greatForm.getText('name');
130+
```
131+
132+
### 5. Disposing of Form Resources
133+
Dispose of the form when not in use:
134+
135+
```dart
136+
greatForm.dispose();
137+
```
138+
139+
## Custom Validators
140+
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.
141+
142+
### Example:
143+
Custom validation to ensure the input contains at least two words:
144+
145+
```dart
146+
FancyInput(
147+
id: 'name',
148+
rules: (value) => [
149+
FancyValidator.notEmpty(value),
150+
() {
151+
if (value.trim().split(' ').length < 2) {
152+
return 'Please enter your full name.';
153+
}
154+
return null;
155+
},
156+
],
157+
)
158+
```
159+
160+
## Contributions
161+
162+
Contributions are welcome! If you want to contribute to this project, please follow these steps:
163+
164+
1. **Fork this repository.**
165+
2. **Create a new branch for your modification.**
166+
3. **Make your changes and submit a pull request.**
167+
168+
## License
169+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: fancy_form
22
description: A flexible and easy-to-use form management solution for Flutter.
3-
version: 1.0.0
3+
version: 1.0.0+1
44
repository: https://github.com/MusilyApp/dart_ytmusic_api.git
55

66
environment:

0 commit comments

Comments
 (0)