GroupBuilder class

A widget that automatically rebuilds the interface based on changes to the state of a GroupController.

The GroupBuilder is similar to a ValueListenableBuilder, but is specifically for managing groups of fields in Formy. It watches a GroupController and rebuilds the widget whenever the group state changes.

This widget is useful for building complex interfaces that depend on the state of a group of form fields.

Properties

  • controller: The GroupController this widget will watch.
  • child: A static widget that will not be rebuilt when the group state changes.
  • builder: A function that returns the widget to be rebuilt. It receives:
    • context: The BuildContext from the widget tree.
    • group: The GroupController being observed.
    • child: The static widget defined in the child property.
  • buildWhen: An optional function that returns true if the widget should rebuild. It receives:
    • oldState: The previous GroupState.
    • currentState: The current GroupState.

Example

GroupBuilder(
  controller: GroupController(
    key: 'key',
    fields: [
      FieldConfig(key: 'field1', validators: [IsRequired()]),
      FieldConfig(key: 'field2', validators: [IsRequired()]),
    ],
  ),
  builder: (context, group, child) {
    return Column(
      children: [
        TestForm(group: group),
        Column(
          children:
              List.generate(group.state.errorMessages.length, (index) {
            return Text(group.state.errorMessages[index]);
          }),
        ),
        ElevatedButton(
          onPressed: group.touchAndValidateAllFields,
          child: const Text('Press'),
        ),
      ],
    );
  },
);

See also

Inheritance

Constructors

GroupBuilder.new({Key? key, required GroupController controller, bool buildWhen(GroupState oldState, GroupState currentState)?, Widget? child, required Widget builder(BuildContext context, GroupController group, Widget? child)})
const

Properties

builder Widget Function(BuildContext context, GroupController group, Widget? child)
A function that returns the widget to be rebuilt.
final
buildWhen bool Function(GroupState oldState, GroupState 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 GroupController
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