ControlledComponentAdapter<T> constructor

const ControlledComponentAdapter<T>({
  1. Key? key,
  2. required Widget builder(
    1. BuildContext context,
    2. ControlledComponentData<T> data
    ),
  3. T? initialValue,
  4. ValueChanged<T>? onChanged,
  5. ComponentController<T>? controller,
  6. bool enabled = true,
})

Creates a ControlledComponentAdapter.

Either controller or initialValue must be provided to establish the component's initial state. The builder function is required and will be called to construct the UI with the current state.

Parameters:

  • builder (required): Function that builds the UI using state data
  • initialValue (T?, optional): Initial value when no controller is used
  • onChanged (ValueChanged
  • controller (ComponentController
  • enabled (bool, default: true): Whether the component accepts user input

Throws AssertionError if neither controller nor initialValue is provided.

Example:

ControlledComponentAdapter<bool>(
  initialValue: false,
  enabled: true,
  builder: (context, data) => Switch(
    value: data.value,
    onChanged: data.enabled ? data.onChanged : null,
  ),
);

Implementation

const ControlledComponentAdapter({
  super.key,
  required this.builder,
  this.initialValue,
  this.onChanged,
  this.controller,
  this.enabled = true,
}) : assert(controller != null || initialValue is T,
          'Either controller or initialValue must be provided');