form_ui_builder library
Dynamic Form UI Builder Library
This library provides a complete solution for building dynamic, data-driven forms in Flutter applications. Forms can be configured via JSON or programmatically and support:
Core Features:
- Dynamic field generation from JSON configuration or parameter map
- Real-time validation as user types
- Conditional field visibility (show/hide based on other field values)
- Auto-calculation of dependent fields (e.g., sum, totals)
- Multi-field validation (e.g., "field A + field B must equal field C")
- Mobile number validation with custom rules
- Range validation (min/max values)
- Focus management and keyboard navigation
Architecture:
- Clean Architecture with separation of concerns
- BLoC pattern for state management
- Dependency injection via GetIt service locator
- Functional programming with Either for error handling (fpdart)
Usage - From JSON (most common):
// 1. Initialize the service locator
setupServiceLocator();
// 2. Build form logic bundle from JSON
final result = buildFormLogicBundle(jsonFormData);
// 3. Use in your UI with FormUiBuilderBloc
BlocProvider(
create: (_) => FormUiBuilderBloc(
buildFormLogicBundle: getIt(),
validateTextFieldValue: getIt(),
// ... other dependencies
),
child: FormUiBuilderScreen(),
)
Usage - From Parameter Map (advanced):
// 1. Initialize the service locator
setupServiceLocator();
// 2. Create or obtain your parameter map
final parameterMap = <int, ChildrenX>{
1: ChildrenX(elementId: 1, elementType: 'ElementText', ...),
2: ChildrenX(elementId: 2, elementType: 'ElementDate', ...),
};
// 3. Build form logic bundle from parameter map
final result = buildFormLogicBundleFromParameterMap(parameterMap);
// 4. Use same as JSON approach
Key Concepts:
FormLogicBundle: Central data structure holding all form state including field configurations, values, visibility states, and dependency relationships.
Dependent Fields: Fields whose values must satisfy constraints based on other fields. Example: "Child fields 10, 11, 12 must sum to parent field 5".
Auto-Calculation: Automatically compute field values from other fields. Example: "Field 20 = Field 15 + Field 16 + Field 17".
Conditional Visibility: Show/hide fields based on selections in other fields. Example: "Show field 14 only when field 13 equals option 1".
Classes
- CardContainer
- CheckboxValueChanged
- CheckNumeric
- Utility class for numeric validation using regular expressions.
- ChildrenX
- DatePickerValueChanged
- DropdownOption
- DropdownValueChanged
- ElementIdGroup
- A value object that represents a group of element IDs.
- FocusNodeChanged
- FormBuilder
- A simplified facade for building forms with less boilerplate.
- FormInputDecoration
- Utility class providing consistent input decoration for form fields.
- FormLogicBundle
- Central data structure that holds all state and configuration for a dynamic form.
- FormSubmissionResult
- FormUiBuilderBloc
- BLoC (Business Logic Component) that manages the state and behavior of dynamic forms.
- FormUiBuilderEvent
- FormUiBuilderScreen
- FormUiBuilderState
- GenerateParameterMap
- InputWrapper
- OptionName
- SubmitForm
- TextFieldFocusChanged
- TextFieldValueChanged
- TimePickerValueChanged
Enums
Properties
- getIt ↔ GetIt
-
getter/setter pair
Functions
-
buildFormLogicBundle(
List< Map< childrenList) → Either<String, dynamic> >Failure, FormLogicBundle> - Builds a FormLogicBundle from a list of form field configurations.
-
buildFormLogicBundleFromParameterMap(
Map< int, ChildrenX> parameterMap) → Either<Failure, FormLogicBundle> - Builds a FormLogicBundle directly from a parameter map of ChildrenX configurations.
-
setupServiceLocator(
) → Future< void> -
showSnackBar(
BuildContext context, String content) → void