SuperForm class
SuperForm container and state manager.
Each individual field should implement SuperFormField with the SuperForm widget as a common ancestor of all of those.
You can use SuperForm.of or pass GlobalKey to be able to retrieve the SuperFormState instance. SuperFormState can be called to update, validate, register, unregister fields or to get their state.
validationMode can be provided to customize when fields are validated.
onSubmit is called when form is submitted and contains no errors.
onChange is called when fields are being modified.
onInit is called right after state is initialized. This can be helpful when you want to manually register a field.
final _formKey = GlobalKey<SuperFormState>();
@override
Widget build(BuildContext context) {
return SuperForm(
key: _formKey,
onInit: (form) {
form.register(
name: "rememberMe",
rules: [],
);
},
onSubmit: (values) {
print(values.toString());
},
child: Column(
children: [
TextSuperFormField(
name: "login",
rules: [Required("Login is required")],
),
SizedBox(height: 8),
TextSuperFormField(
name: "password",
obscureText: true,
rules: [Required("Password is required")],
),
SizedBox(height: 8),
OutlinedButton(
onPressed: () {
_formKey.currentState?.submit();
},
child: Text("Sign in"),
)
],
),
);
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SuperForm
Constructors
-
SuperForm({Key? key, required Widget child, dynamic onSubmit(Map<
String, dynamic> values) = _doNothing, ValidationMode validationMode = ValidationMode.onSubmit, dynamic onInit(SuperFormState form) = _doNothing, dynamic onChange(Map<String, SuperFormFieldData> fields) = _doNothing, Map<String, dynamic> initialValues = const {}, String? restorationId, bool enabled = true}) -
const
Properties
- child → Widget
-
final
- enabled → bool
-
Whether fields should be enabled. Default is true.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
initialValues
→ Map<
String, dynamic> -
Map of initial values which will be obtained by field when registered or reset
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onChange
→ dynamic Function(Map<
String, SuperFormFieldData> fields) -
Called when fields are being modified.
final
- onInit → dynamic Function(SuperFormState form)
-
Called right after state is initialized. This can be helpful
when you want to manually register a field.
final
-
onSubmit
→ dynamic Function(Map<
String, dynamic> values) -
Called when form is submitted and contains no errors.
final
- restorationId → String?
-
Restoration ID to save and restore form values
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- validationMode → ValidationMode
-
Mode in which fields are validated.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → SuperFormState -
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.
override
-
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}) → 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
Static Methods
-
of(
BuildContext context, {bool listen = true}) → SuperFormState - Gets the closest SuperFormState instance.
-
ofField(
BuildContext context, String fieldName) → SuperFormState - Gets the closest SuperFormState instance.
-
ofFieldMaybe(
BuildContext context, String fieldName) → SuperFormState? - Gets the closest SuperFormState instance.
-
ofFieldValue<
T> (BuildContext context, String fieldName) → T? - Gets the field value of the closest SuperFormState instance.
-
ofMaybe(
BuildContext context, {bool listen = true}) → SuperFormState? - Gets the closest SuperFormState instance.