flutter_smart_forms 1.0.0
flutter_smart_forms: ^1.0.0 copied to clipboard
A powerful, reactive, and dynamic form builder for Flutter supporting JSON-driven forms, conditional fields, validation, and custom UI components.
๐ flutter_smart_forms #
Flutter Smart Forms is a powerful, reactive, and dynamic form builder for Flutter that allows developers to build complex forms using JSON or Flutter widgets with minimal boilerplate.
It includes validation, async validation, conditional fields, icons, dynamic visibility, showClearIcon inputs, and reactive state management.
Build powerful forms once and control them dynamically through APIs or JSON.
โจ Features #
- โ JSON-driven forms
- โ Widget-driven forms
- โ Reactive field updates
- โ Real-time value tracking
- โ Synchronous validation
- โ Async validation
- โ Conditional field visibility
- โ Enable/disable fields dynamically
- โ Readonly fields
- โ showClearIcon input fields
- โ Date / Time / DateTime picker support
- โ Icon support
- โ Nested array support
- โ File / Image upload support
- โ Signature pad
- โ Fully customizable UI
- โ Simple developer API
- โ Extendable architecture
๐งฉ Supported Field Types #
| Field Type | Supported |
|---|---|
| Text | โ |
| Multiline Text | โ |
| โ | |
| Phone | โ |
| Password | โ |
| Dropdown | โ |
| Multi Select | โ |
| Checkbox | โ |
| Radio | โ |
| Switch | โ |
| Date Picker | โ |
| Time Picker | โ |
| DateTime Picker | โ |
| File Upload | โ |
| Image Upload | โ |
| Suggestion/AutoComplete | โ |
| Signature Pad | โ |
| Barcode Scanner | โ |
| Rating | โ |
More fields will be added in future releases.
๐ฆ Installation #
Add the package to pubspec.yaml
dependencies:
flutter_smart_forms: ^1.0.0
Run
flutter pub get
๐ Quick Start #
Create a form quickly using Flutter widgets.
import 'package:flutter_smart_forms/flutter_smart_forms.dart';
final formController = SmartFormController();
SmartForm(
controller: formController,
children: [
TextFieldField(
"name",
label: "Full Name",
showClearIcon: true,
),
EmailField(
"email",
label: "Email Address",
),
PasswordField(
"password",
label: "Password",
),
DropdownField(
"country",
label: "Country",
items: ["India", "USA", "UK"],
),
],
onSubmit: (values) {
print(values);
},
);
Example output
{
name: John,
email: john@email.com,
password: ****,
country: India
}
๐ง JSON Driven Forms #
Forms can also be created dynamically using JSON.
final jsonForm = [
{
"type": "text",
"key": "name",
"label": "Full Name",
"placeholder": "Enter your full name",
"showClearIcon": true
},
{
"type": "email",
"key": "email",
"label": "Email Address"
},
{
"type": "password",
"key": "password",
"label": "Password"
},
{
"type": "dropdown",
"key": "country",
"label": "Country",
"items": ["India", "USA", "UK"]
}
];
Use JSON in SmartForm
final fields = jsonForm.map((e) => FieldModel.fromJson(e)).toList();
SmartForm(
controller: controller,
fields: fields,
onSubmit: (values) {
print(values);
},
);
๐งพ FieldModel List #
You can also define forms directly using FieldModel:
final fields = [
FieldModel(
type: 'text',
key: 'firstName',
label: 'First Name',
placeholder: 'Enter first name',
defaultValue: 'Alice',
extra: {'disabled': true},
),
FieldModel(
type: 'text',
key: 'lastName',
label: 'Last Name',
defaultValue: 'R',
),
FieldModel(
type: 'text',
key: 'fullName',
label: 'Full Name',
defaultValueCallback: (values) {
final first = values['firstName'] ?? '';
final last = values['lastName'] ?? '';
return '$first $last';
},
),
];
โ Conditional / Reactive Fields #
FieldModel(
type: "text",
key: "company_name",
label: "Company Name",
visibleIf: {"user_type": "company"},
)
watchFields ensures dependent fields update reactively.
FieldModel(
type: 'dropdown',
key: 'state',
watchFields: ['country'],
visibleIf: {'country': 'US'},
)
๐ Date / Time / DateTime Picker #
FieldModel(
type: "date",
key: "meeting_time",
label: "Meeting Time",
dateMode: "datetime", // date / time / datetime
)
โ Validation #
EmailField(
"email",
validators: [Validators.required, Validators.email],
)
{
"type": "text",
"key": "firstName",
"label": "First Name",
"placeholder": "Enter first name",
"default": "Johna",
"validators": "required|min:2",
},
Built-in validators:
- required, email, phone, numeric, minLength, maxLength, passwordStrength
Supports custom & async validators:
EmailField(
"email",
asyncValidator: (value) async {
await Future.delayed(Duration(seconds: 1));
if (value == "test@email.com") return "Email already exists";
return null;
},
)
๐ File / Image Upload Extra Options #
| Parameter | Type | Description |
|---|---|---|
| uploadText | String | Upload button text |
| uploadIcon | String | Icon type: cloud / image |
| multiple | bool | Allow multiple files/images |
| compress | bool | Enable compression |
| compressQuality | int | Compression quality 0โ100 |
| preview | bool | Show preview |
| removable | bool | Allow remove |
| crop | bool | Enable crop (image only) |
| cropStyle | String | rectangle / circle |
| cropAspectRatio | Map | e.g., {"x":1,"y":1} |
๐ Nested Arrays #
FieldModel(
type: 'array',
key: 'addresses',
label: 'Addresses',
extra: {'minItems': 1, 'maxItems': 5},
fields: [
FieldModel(type: 'text', key: 'street', label: 'Street'),
FieldModel(type: 'text', key: 'city', label: 'City'),
],
)
Supports nested arrays for complex structures like Orders โ Items โ Subitems.
๐ SmartFormController #
- Full reactive form control
- Get/set field values
- Validation
- Reset
- Access all form values
final controller = SmartFormController();
controller.setValue("name", "John");
final email = controller.getValue("email");
controller.validate();
controller.reset();
final allValues = controller.values;
๐จ Custom Submit Button #
SmartForm(
controller: controller,
fields: fields,
submitText: "Create Account",
submitButtonStyle: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
padding: EdgeInsets.symmetric(vertical: 16),
),
onSubmit: (values) {
print(values);
},
);
Convert JSON to fields
final fields = json.map((e) => FieldModel.fromJson(e)).toList();
๐ Date / Time Picker #
You can control picker type using dateMode.
Supported values
date
time
datetime
Example
FieldModel(
type: "date",
key: "meeting_time",
label: "Meeting Time",
dateMode: "datetime",
)
Examples
| Mode | Result |
|---|---|
| date | Date Picker |
| time | Time Picker |
| datetime | Date + Time Picker |
โ showClearIcon Fields #
Fields can show a clear icon to reset input.
TextFieldField(
"name",
label: "Name",
showClearIcon: true,
)
๐ Conditional Fields #
Show fields based on other field values.
Example
Show company_name if user_type == company
FieldModel(
type: "text",
key: "company_name",
label: "Company Name",
visibleWhen: {
"field": "user_type",
"equals": "company"
},
)
โ Built-in Validation #
Add validators easily.
EmailField(
"email",
validators: [
Validators.required,
Validators.email,
],
)
Available validators
โข required โข email โข phone โข numeric โข minLength โข maxLength โข passwordStrength
You can also create custom validators.
โณ Async Validation #
Example checking email availability.
EmailField(
"email",
asyncValidator: (value) async {
await Future.delayed(Duration(seconds: 1));
if (value == "test@email.com") {
return "Email already exists";
}
return null;
},
)
๐ SmartFormController #
The controller allows full control of the form.
Create controller
final form = SmartFormController();
Get field value
form.getValue("email");
Set field value
form.setValue("name", "John");
Get all form values
form.values
Validate form
form.validate();
Reset form
form.reset();
๐จ Custom Submit Button #
Customize submit button.
SmartForm(
controller: controller,
fields: fields,
submitText: "Create Account",
submitButtonStyle: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
padding: EdgeInsets.symmetric(vertical: 16),
),
onSubmit: (values) {
print(values);
},
);
๐ Example Project #
A full example is available inside
example/lib/main.dart
Run it to explore all field types.
๐บ Roadmap #
Upcoming features
โข Multi-step forms โข Form stepper wizard โข Drag & drop form builder โข Dynamic sections โข Form analytics
๐ค Contributing #
Contributions are welcome.
Steps:
- Fork the repository
- Create a new feature branch
- Commit changes
- Open a Pull Request
๐ Issues #
If you find a bug or want to request a feature, please open an issue in the repository.
๐ License #
MIT License
โญ Support #
If you like this package:
โข โญ Star the repository โข ๐ Like the package on pub.dev
Your support helps the project grow.
๐ Keywords #
Flutter dynamic forms Flutter form builder Flutter JSON forms Flutter validation Flutter dynamic form generator Flutter async validation Flutter form engine Flutter CMS forms Flutter reactive forms Flutter form builder package