cdx_components
Flutter UI library with form builders, reactive widgets, theme and app services, and utilities for fast, consistent app development. Useful for data-driven apps, admin panels, and anything that needs rich forms, a shared theme, and optional backend/CRUD glue.
What it does
Forms
- CdxFormBuilder + FormBuilderController: build reactive forms from a stream of
FormItemmaps; validation and values in one place. - FormItem supports many types:
text,password,multiline,number,intNumber,date,dropdown,multiselect,checkbox,radio,image,images,checkArray,customArray,dragArray,custom,none. Optional: in-row layout, break row/col, visibility streams, custom builders, object/array mapping. - InnerForm: nested forms and sub-forms with their own controller.
- FormArray / FormArrayCustom / FormArrayReorderable: repeatable blocks and drag-to-reorder.
- Stepper support (multi-step forms) and configurable FormStrategy (e.g. controller disposal, focus).
Theme and DI
- IThemeService: light/dark
ColorSet,CdxInputThemeData,CdxButtonThemeData, paddings/radius per screen type (mobile, tablet, desktop). Use DI.theme() and DI.colors() in widgets. - IAppService, IMediaService, IEventService: pluggable app/theme/media/event hooks; you implement and register with GetIt, the library calls them where needed (toast, dialogs, image upload, events).
- DI facade:
DI.theme(),DI.app(),DI.media(),DI.events().
UI widgets
- Buttons:
PrimaryButton,AccentButton,ErrorButton, outline variants,CustomColorButton(custom colors), optional loading and icons. - Inputs:
InputTextField(wraps TextField with theme, errors, keyboard actions), ReactiveImage, CustomColorPicker. - Reactive controls:
ReactiveDropdownButton,ReactiveMultiSelect,ReactiveCheckbox,ReactiveRadio,ReactiveArrayItem, MultiImage (all RxDart-friendly). - Layout / data:
CustomTable,CustomGrid, StatusWidget (loading/error/idle), DataBuilder, UserAvatar. Item list: Default, DefaultSettingRow, ItemListTemplate.
Cloud and data
- ICRUDService and CRUD service implementations with configurable strategies (e.g. push/force update). Platform interfaces: IDatabasePlatform, IFunctionsPlatform (for backend/cloud integration).
Utilities
- Extensions:
IntExtension,DoubleExtension,StringExtension(e.g.formatTime,normalizedNumber,isValidE164PhoneNumber,toPrice,toPercentage), list helpers. - Throttle / Debounce handlers for events.
- NumericRangeFormatter / NumericIntRangeFormatter for numeric fields.
- Pair, Triple, Quadruple, … (t_uple.dart), DropdownItem, FormType enum, Result and result types.
Installation
Add to your pubspec.yaml:
dependencies:
cdx_components: ^1.0.0
Then run:
flutter pub get
Quick start
Dependency injection and theme
Register your app/theme/media/event services, then run the app:
import 'package:cdx_components/injector.dart';
import 'package:cdx_components/core/services/app/iapp_service.dart';
import 'package:cdx_components/core/services/app/itheme_service.dart';
// ... your service implementations
void main() {
GetIt.I.registerSingleton<IThemeService>(MyThemeService());
GetIt.I.registerSingleton<IAppService>(MyAppService(/* ... */));
// IMediaService, IEventService as needed
runApp(const MyApp());
}
Use DI.theme(), DI.app(), etc. where the library expects these services.
CdxFormBuilder with FormItem
Build a reactive form with FormBuilderController and CdxFormBuilder:
import 'package:cdx_components/core/models/form_item.dart';
import 'package:cdx_components/core/models/dropdown_item.dart';
import 'package:cdx_components/core/models/t_uple.dart';
import 'package:cdx_components/form/builder.dart';
import 'package:cdx_components/form/controller.dart';
import 'package:cdx_components/form/models/strategy.dart';
import 'package:cdx_components/injector.dart';
import 'package:flutter/material.dart';
import 'package:rxdart/rxdart.dart';
// In your State:
final _subject = BehaviorSubject<Pair<bool, Map<String, dynamic>>>();
final _formMap = BehaviorSubject<Map<String, FormItem>>.seeded({});
late final FormBuilderController _controller = FormBuilderController(
subject: _subject,
formMap: _formMap,
focusMap: const {},
strategy: FormStrategy.defaultStrategy,
inputTheme: DI.theme().inputTheme,
);
void initForm() {
_formMap.add({
'name': FormItem(
hint: 'Name',
type: FormType.text,
value: '',
validation: (v) => v?.toString().isNotEmpty == true,
),
'country': FormItem<DropdownItem?>(
hint: 'Country',
type: FormType.dropdown,
value: null,
validation: (v) => v != null,
options: [
DropdownItem(title: 'Italy', value: 'IT'),
DropdownItem(title: 'France', value: 'FR'),
],
),
});
}
// In build:
CdxFormBuilder(
controller: _controller,
hintStyle: TextStyle(color: DI.colors().minorText, fontSize: 12),
showErrorsStream: showErrorsSubject.stream,
errorMessage: 'Please fill the field',
);
Remember to dispose the controller and subjects in your State.dispose().
Buttons
import 'package:cdx_components/widgets/custom_button.dart';
PrimaryButton(onPressed: () {}, text: 'Save');
AccentButton(onPressed: () {}, text: 'Submit');
Example app
The example/ app shows:
- Registering theme, app, media, and event services with GetIt.
- A form built with
CdxFormBuilderandFormBuilderController(text, multiline, dropdown). - Use of
PrimaryButtonand validation error display.
Run it from the package root:
cd example && flutter run
Package structure
lib/app/– Constants, components base, mappings (extend for your app).lib/core/models/– FormItem, FormType, theme data, dropdown/item types, result types.lib/core/services/– App/theme/media/event interfaces; cloud CRUD and platform interfaces.lib/form/–FormBuilderController,CdxFormBuilder(form builder widget).lib/widgets/– Buttons, reactive widgets, tables, InnerForm, etc.lib/utils/– Extensions, throttle/debounce, numeric formatters.lib/injector.dart–DIfacade.
Import what you need from subpaths, for example:
package:cdx_components/form/builder.dart– CdxFormBuilderpackage:cdx_components/form/controller.dart– FormBuilderControllerpackage:cdx_components/core/models/form_item.dartpackage:cdx_components/injector.dart
Requirements
- Dart
^3.10.1 - Flutter
>=1.17.0
License
Apache-2.0. See LICENSE.
Libraries
- app/components
- app/constants
- app/mappings
- constants
- core/models/base_object
- core/models/color_set
- core/models/data_sheet
- core/models/dropdown_item
- core/models/feature
- core/models/filter_wrapper
- core/models/form_array_item
- core/models/form_item
- core/models/iapp_notification
- core/models/ibase_object
- core/models/input_status
- core/models/input_theme_data
- core/models/list_item
- core/models/multiselect_item
- core/models/pic_data_image
- core/models/pic_data_wrapper
- core/models/pic_media_image
- core/models/result
- core/models/result_callback
- core/models/result_data
- core/models/t_uple
- core/models/tab_data
- core/models/table_header
- core/models/user_notification
- core/models/widget_size
- core/services/app/iapp_service
- core/services/app/ievent_service
- core/services/app/imedia_service
- core/services/app/itheme_service
- core/services/cloud/crud_service
- core/services/cloud/icrud_service
- core/services/cloud_platform/idatabase_platform
- core/services/cloud_platform/ifunctions_platform
- form/builder
- form/controller
- form/models/strategy
- injector
- utils/extensions
- utils/numeric_range_formatter
- utils/timed_event/debounce
- utils/timed_event/handler
- utils/timed_event/throttle
- widgets/color_picker
- widgets/custom_grid
- widgets/custom_table
- widgets/custom_widget_state
- widgets/data_builder
- widgets/form_array
- widgets/form_array_custom
- widgets/form_array_reorderable
- widgets/inner_form
- widgets/input_text_field
- widgets/item_list/default
- widgets/item_list/default_settings_row
- widgets/item_list/template
- widgets/multi_image
- widgets/reactive_array_item
- widgets/reactive_checkbox
- widgets/reactive_custom
- widgets/reactive_dropdown_button
- widgets/reactive_image
- widgets/reactive_multiselect
- widgets/reactive_radio
- widgets/status_widget
- widgets/user_avatar