AnyFormField<T> class

A form-enabled wrapper around AnyField that provides form integration and validation.

AnyFormField combines the flexibility of AnyField with Flutter's form functionality, allowing it to be used within Form widgets with validation, saving, and error display capabilities.

Example usage:

Form(
  key: _formKey,
  child: AnyFormField<List<String>>(
    displayBuilder: (context, tags) => Wrap(
      children: tags.map((t) => Chip(label: Text(t))).toList(),
    ),
    decoration: InputDecoration(labelText: 'Tags'),
    validator: (value) {
      if (value?.isEmpty ?? true) return 'Please add at least one tag';
      return null;
    },
    onSaved: (value) => _savedTags = value,
    onTap: (currentTags) async {
      final result = await showTagSelector(
        context,
        initialTags: currentTags ?? []
      );
      if (result != null) {
        // Form field handles controller update
      }
    },
  ),
)
Inheritance

Constructors

AnyFormField({Key? key, required Widget displayBuilder(BuildContext context, T value), required InputDecoration decoration, double? minHeight, double? maxHeight, AnyValueController<T>? controller, ValueChanged<T?>? onChanged, FutureOr onTap(T? value)?, T? initialValue, FormFieldValidator<T>? validator, FormFieldSetter<T>? onSaved})
const

Properties

controller AnyValueController<T>?
Optional controller that manages the field's value.
final
decoration InputDecoration
Decoration to customize the appearance of the field.
final
displayBuilder Widget Function(BuildContext context, T value)
Function that builds the widget to display the current value.
final
hashCode int
The hash code for this object.
no setterinherited
initialValue → T?
Initial value for the field when no controller is provided.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
maxHeight double?
Maximum height the field can expand to in logical pixels.
final
minHeight double?
Minimum height of the field in logical pixels.
final
onChanged ValueChanged<T?>?
Callback that is invoked when the field's value changes.
final
onSaved FormFieldSetter<T>?
Optional callback fired when Form.save is called.
final
onTap FutureOr Function(T? value)?
Callback that is invoked when the field is tapped.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
validator FormFieldValidator<T>?
Optional validator function called when Form.validate is called.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<AnyFormField<T>>
Creates the mutable state for this widget at a given location in the tree.
override
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