๐ŸŒŸ 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.


๐Ÿ“ธ Demo

JSON Dynamic Form

Dynamic JSON Form

Complex JSON Form Layout

Dynamic JSON Form Example

File & Image Upload

File Upload

Validation Demo

Validation

Dropdown Demo


โšก 30 Second Example

Create a fully working form in seconds.

import 'package:flutter_smart_forms/flutter_smart_forms.dart';

final controller = SmartFormController();

SmartForm(
  controller: controller,
  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);
  },
);

Result

{
"name": "John",
"email": "john@email.com",
"password": "****",
"country": "India"
}

โœจ 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
  • โœ… Barcode scanner
  • โœ… Fully customizable UI
  • โœ… Simple developer API
  • โœ… Extendable architecture

Why flutter_smart_forms?

flutter_smart_forms simplifies building complex dynamic forms in Flutter.

Instead of writing hundreds of lines of UI code, forms can be defined using:

โ€ข JSON โ€ข FieldModel โ€ข Flutter widgets

This makes it ideal for:

โ€ข Admin dashboards โ€ข CMS driven apps โ€ข Enterprise applications โ€ข Dynamic form APIs

Feature flutter_smart_forms flutter_form_builder reactive_forms
JSON driven forms โœ… โŒ โŒ
Conditional fields โœ… โš ๏ธ โš ๏ธ
Async validation โœ… โœ… โœ…
File upload โœ… โŒ โŒ
Signature pad โœ… โŒ โŒ
Nested arrays โœ… โš ๏ธ โš ๏ธ

Architecture Diagram

JSON / Widgets
      โ†“
FieldModel
      โ†“
SmartFormController
      โ†“
Reactive Fields
      โ†“
UI Rendering

๐Ÿงฉ Supported Field Types

Field Type Supported
Text โœ…
Multiline Text โœ…
Email โœ…
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 your pubspec.yaml

dependencies:
  flutter_smart_forms: ^1.0.1

Run

flutter pub get

๐Ÿš€ Quick Start

Create a form 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 Example

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

Show fields dynamically based on other field values.

FieldModel(
  type: "text",
  key: "company_name",
  label: "Company Name",
  visibleIf: {"user_type": "company"},
)

Reactive dependency example:

FieldModel(
  type: 'dropdown',
  key: 'state',
  watchFields: ['country'],
  visibleIf: {'country': 'US'},
)

๐Ÿ“… Date / Time / DateTime Picker

Control picker type using dateMode.

Supported values

date
time
datetime

Example

FieldModel(
  type: "date",
  key: "meeting_time",
  label: "Meeting Time",
  dateMode: "datetime",
)
Mode Result
date Date Picker
time Time Picker
datetime Date + Time Picker

โœ” Validation

Widget example

EmailField(
  "email",
  validators: [
    Validators.required,
    Validators.email,
  ],
)

JSON example

{
  "type": "text",
  "key": "firstName",
  "label": "First Name",
  "validators": "required|min:2"
}

Available validators

  • required
  • required_if:userType,admin
  • required_unless:isGuest,true
  • email
  • phone
  • url
  • min:3
  • max:20
  • between:3,10
  • after:2024-01-01
  • fileType:jpg,png,pdf
  • regex
  • match:password
  • async:emailAvailable

Dependent Validators

Rule Example Meaning
same same:password Must be equal
different different:username Must NOT be equal
in in:admin,user,manager Value must be in list
not_in not_in:test,guest Value must NOT be in list
confirmed confirmed Must match field_confirmation
accepted accepted Must be true/yes/1

Smart Error Messages

{
"type": "text",
"key": "username",
"label": "Username",
"validators": "required|min:3|max:10",
"messages": {
"required": "Username is required",
"min": "Username must be at least :min characters",
"max": "Username cannot exceed :max characters"
}
}

โณ 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;
  },
)

๐Ÿ—‚ File / Image Upload Options

Parameter Type Description
uploadText String Upload button text
uploadIcon String Icon type: cloud / image
multiple bool Allow multiple files
compress bool Enable compression
compressQuality int Compression quality
preview bool Show preview
removable bool Allow remove
crop bool Enable crop
cropStyle String rectangle / circle
cropAspectRatio Map Example { "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 complex structures like:

Orders
 โ”” Items
    โ”” Sub Items

๐ŸŽ› SmartFormController

Provides full control over form state.

Create controller

final controller = SmartFormController();

Set value

controller.setValue("name", "John");

Get value

controller.getValue("email");

Validate form

controller.validate();

Validate on button click

await controller.validateFields([
"email",
"password",
"phone"
]);
ElevatedButton(
  onPressed: () async {
    final valid = await controller.validateField("email");

    if (valid) {
      print("Email valid");
    }
  },
  child: Text("Check Email"),
)

Reset form

controller.reset();

Get all values

controller.values

Register custom validator

Validators.register("noAdmin", (value, param) {
  if (value == "admin") {
    return "Admin is not allowed";
  }
  return null;
});

๐ŸŽจ 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);
  },
);

๐Ÿ“‚ Example Project

A full example is available inside

example/lib/main.dart

Run the example to explore all field types.


๐Ÿ—บ Roadmap

Upcoming features

โ€ข Multi-step wizard forms โ€ข Remote API driven forms โ€ข Form auto-save persistence โ€ข Dynamic sections โ€ข Drag & drop form builder


๐Ÿค Contributing

Contributions are welcome.

Steps

  1. Fork the repository
  2. Create a new feature branch
  3. Commit your changes
  4. 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