A powerful Flutter package for building dynamic forms from JSON definitions. Create complex forms with validation, error handling, conditional logic, and flexible layouts without writing repetitive UI code.
Dynamic Form Generation - Build forms directly from JSON schemas
Field Validation - Built-in validators (required, email, custom patterns, field matching)
Error Handling - Comprehensive error display and validation feedback
Multiple Input Types - Text, email, password, number, checkbox, radio buttons, dropdowns
Flexible Layouts - Horizontal and vertical field arrangements
Conditional Logic - Show/hide and enable/disable fields based on other field values
Form Submission - Easy form data collection and validation
Customizable - Easily extendable for custom widgets and styling
- Text Fields:
text,email,password,number,phone - Selection:
datetime,checkbox,radio,select(dropdown) - Validation: Required fields, email validation, custom patterns, field matching
- Conditional Logic: Show/hide rules, enable/disable rules
Add this to your package's pubspec.yaml file:
dependencies:
json_form_builder: ^0.1.0Then run:
flutter pub getimport 'package:flutter/material.dart';
import 'package:json_form_builder/json_form_builder.dart';
import 'package:json_form_builder/models/json_form.dart';
class MyFormPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Define your JSON schema
final jsonSchema = {
"title": "User Registration",
"subtitle": "Please fill in your details",
"groups": [
{
"title": "Personal Information",
"elements": [
{
"layout": "vertical",
"fields": [
{
"key": "firstName",
"format": "text",
"label": "First Name",
"placeholder": "Enter your first name",
"validators": [
{"key": "required", "message": "First name is required"}
]
},
{
"key": "email",
"format": "email",
"label": "Email",
"placeholder": "Enter your email",
"validators": [
{"key": "required", "message": "Email is required"}
]
}
]
}
]
}
]
};
final jsonForm = JsonForm.fromJson(jsonSchema);
return Scaffold(
appBar: AppBar(title: Text('Dynamic Form')),
body: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: JsonFormBuilder(
jsonForm: jsonForm,
onSubmit: (formData) {
print('Form submitted with data: $formData');
// Handle form submission
},
),
),
);
}
}{
"key": "hasAccount",
"format": "checkbox",
"label": "I already have an account"
},
{
"key": "password",
"format": "password",
"label": "Password",
"rule": {
"type": "SHOW",
"field": "hasAccount",
"value": true
},
"validators": [
{"key": "required", "message": "Password is required"}
]
}{
"key": "gender",
"format": "radio",
"label": "Gender",
"options_layout": "horizontal",
"options": [
{"label": "Male", "value": "male"},
{"label": "Female", "value": "female"},
{"label": "Other", "value": "other"}
],
"validators": [
{"key": "required", "message": "Please select your gender"}
]
}{
"key": "country",
"format": "select",
"label": "Country",
"placeholder": "Select your country",
"options": [
{"label": "United States", "value": "us"},
{"label": "Canada", "value": "ca"},
{"label": "United Kingdom", "value": "uk"}
],
"validators": [
{"key": "required", "message": "Country is required"}
]
}{
"key": "confirmPassword",
"format": "password",
"label": "Confirm Password",
"validators": [
{"key": "required", "message": "Please confirm your password"},
{"key": "match", "field": "password", "message": "Passwords do not match"}
]
}{
"title": "Form Title", // Optional form title
"subtitle": "Form Subtitle", // Optional form subtitle
"groups": [ // Array of form groups
{
"title": "Group Title", // Optional group title
"elements": [ // Array of form elements
{
"layout": "horizontal", // "horizontal" or "vertical"
"fields": [ // Array of form fields
{
"key": "fieldKey", // Unique field identifier
"format": "text", // Field type
"label": "Field Label", // Field label
"placeholder": "Placeholder", // Optional placeholder
"value": "default_value", // Optional default value
"validators": [...], // Optional validators
"rule": {...}, // Optional conditional rule
"options": [...], // For select/radio fields
"options_layout": "horizontal" // For radio button layout
}
]
}
]
}
]
}text- Basic text inputemail- Email input with email keyboardpassword- Password input (obscured text)number- Numeric input with number keyboardphone- Numeric input with phone keyboarddatetime- DateTime input with date picker modalcheckbox- Boolean checkboxradio- Single selection from optionsselect- Dropdown selection
required- Field must have a valuematch- Field must match another field's valueformat- Field must match with the provided patternminLength- Field length must be greater or equal to provided valuemaxLength- Field length must be shorter or equal to provided value
"rule": {
"type": "SHOW",
"field": "otherFieldKey",
"value": expectedValue
}"rule": {
"type": "DISABLE",
"field": "otherFieldKey",
"value": expectedValue
}Check out the example directory for a complete working example with:
- Simple form demo
- Complex form with all field types
- Conditional logic examples
- Widgetbook integration for testing
To run the example:
cd example
flutter run lib\widgetbook.dartContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
For bugs and feature requests, please file an issue on the GitHub repository.