ControlledComponentAdapter<T> constructor
const
ControlledComponentAdapter<T> ({
- Key? key,
- required Widget builder(
- BuildContext context,
- ControlledComponentData<
T> data
- T? initialValue,
- ValueChanged<
T> ? onChanged, - ComponentController<
T> ? controller, - 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 datainitialValue
(T?, optional): Initial value when no controller is usedonChanged
(ValueChangedcontroller
(ComponentControllerenabled
(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');