FieldBuilder<T> class
A widget that automatically rebuilds the interface based on changes to the state of a FieldController.
The FieldBuilder is similar to a ValueListenableBuilder
, but is
specific for managing Formy fields. It watches a FieldController
and rebuilds the widget whenever the field state changes.
This widget is useful to build complex interfaces that depend on the state of a form field.
Properties
- controller: The FieldController this widget will watch.
- child: A static widget that will not be rebuilt when the field state changes.
- builder: A function that returns the widget to be rebuilt. It receives:
context
: The BuildContext from the widget tree.field
: The FieldController being observed.child
: The static widget defined in thechild
property.
- buildWhen: An optional function that returns
true
if the widget should rebuild. It receives:oldState
: The previous FieldState.currentState
: The current FieldState.
Example
FieldBuilder<String>(
controller: FieldController(key: 'key'),
builder: (context, field, child) {
return TextField(
controller: TextEditingController(text: field.value),
decoration: InputDecoration(
labelText: 'Name',
errorText: field.firstError,
),
onChanged: field.update,
);
},
)
See also
- FieldController, which manages the state of a field.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- FormyBuilder<
FieldController< T> , FieldState<T> > - FieldBuilder
Constructors
-
FieldBuilder.new({Key? key, required FieldController<
T> controller, bool buildWhen(FieldState<T> oldState, FieldState<T> currentState)?, Widget? child, required Widget builder(BuildContext context, FieldController<T> field, Widget? child)}) -
const
Properties
-
builder
→ Widget Function(BuildContext context, FieldController<
T> field, Widget? child) -
A function that returns the widget to be rebuilt.
final
-
buildWhen
→ bool Function(FieldState<
T> oldState, FieldState<T> currentState)? -
An optional function that returns
true
if the widget should rebuild.finalinherited - child → Widget?
-
A static widget that will not be rebuilt when the state changes.
finalinherited
-
controller
→ FieldController<
T> -
The FieldController or GroupController that this widget will watch.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< StatefulWidget> -
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