ControlValueAcessor<T, V> class
abstract
An abstract base class to build custom form input widgets that connect a FormControl or a FormGroup to the widget tree.
This is inspired by Angular's ControlValueAccessor
, providing a clean
interface to bind reactive controls to Flutter widgets.
Use this class as a base for widgets that need to:
- Read and write values to/from a FormControl.
- Integrate with validation and disabled/read-only state.
- Listen to changes in the form control's state.
Example usage:
class CustomInput extends ControlValueAcessor<String, String> {
const CustomInput({super.key, required super.formGroup, required super.name});
@override
Widget build(BuildContext context) {
return TextField(
controller: textController,
decoration: InputDecoration(errorText: error),
onChanged: (val) => value = val,
);
}
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- ControlValueAcessor
Constructors
-
ControlValueAcessor.new({Key? key, bool enabled = true, bool required = false, FormGroup? formGroup, String? name, FormControl<
T, V> ? control, FormFieldValidator? validator}) -
Creates a ControlValueAcessor.
const
Properties
- changeNotifier → ChangeNotifier
-
Returns the ChangeNotifier associated with this control.
no setter
-
control
→ FormControl<
T, V> -
Returns the FormControl for this accessor.
no setter
- enabled → bool
-
Whether this field is enabled.
final
- error → String?
-
Returns the validation error message, if any.
no setter
- formGroup → FormGroup?
-
The FormGroup this accessor binds to (if using a named control).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisabled → bool
-
Whether this control is disabled.
no setter
- isRequired → bool
-
Whether this control is required.
no setter
- isValid → bool
-
Whether this control is currently valid.
no setter
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- name → String?
-
The name of the control inside the FormGroup.
final
- required → bool
-
Whether this field is required.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- textController → TextEditingController
-
Returns the TextEditingController if this control is a text control.
no setter
- validator → FormFieldValidator?
-
The validator function for this control.
no setter
- value ↔ V
-
Returns the current value of this control.
getter/setter pair
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited