GFormController class final
Coordinates a Flutter Form and named text controllers.
This is intentionally small: it handles the repetitive form key, validate/save/reset flow, and controller disposal for forms that do not need a larger state-management solution.
- Inheritance
-
- Object
- ChangeNotifier
- GFormController
- Available extensions
Constructors
-
GFormController({GlobalKey<
FormState> ? key}) -
Creates a controller. Pass an existing
keyto reuse a form key, or omit it to have one created automatically.
Properties
- hasErrors → bool
-
Whether any field currently fails validation.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isDirty → bool
-
Whether any named field differs from its pristine value.
no setter
-
key
→ GlobalKey<
FormState> -
The GlobalKey attached to the underlying Flutter Form.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → FormState?
-
The current FormState, or
nullif the form has not been mounted yet.no setter - submitting → bool
-
Whether submit is currently in flight.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
bindTextController(
String name, TextEditingController controller, {GFormValueParser? parser}) → void - Attaches an existing text controller to a named form field.
-
bindTextValidator(
String name, String? validator(String?)?) → void - Records the validator a named text field is using.
-
build(
Widget builder(BuildContext context)) → Widget -
Available on Listenable, provided by the ListenableX extension
Builds a reactive ListenableBuilder widget for this listenable. -
changedTextValues(
) → Map< String, String> - Only the text values that changed since the last pristine mark.
-
clearText(
String name) → void -
Clears the text of the field registered under
name. -
dispose(
) → void -
Discards any resources used by the object.
override
-
errorOf(
String name) → String? -
The current validation message for
name, ornullwhen it passes. -
errors(
) → Map< String, String> - Every current validation message, keyed by field name.
-
field<
T> (String name, {T? initialValue, GTypedFormValidator< T> ? validator}) → GFormFieldController<T> -
Creates or returns a typed field controller for
name. -
focusFirstInvalid(
) → bool - Focuses the first field that currently fails validation.
-
focusNode(
String name) → FocusNode -
Returns the FocusNode registered under
name, creating one if needed. -
isFieldDirty(
String name) → bool -
Whether
namediffers from the value it was last marked pristine at. -
markPristine(
) → void - Treats the current values as the new baseline for isDirty and reset.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
patchText(
Map< String, String> values) → void -
Applies
valuesto the matching named fields. -
registerField<
T> (GFormFieldController< T> field) → GFormFieldController<T> - Registers a typed field controller.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
requestFocus(
String name) → void -
Moves focus to the field registered under
name. -
reset(
) → void - Resets the form to its pristine baseline.
-
save(
) → void -
Calls
onSavedon every field. -
setText(
String name, String value) → void -
Replaces the text of the field registered under
nameand parks the caret at the end. -
setValue<
T> (String name, T? value) → void - Updates a typed field value.
-
submit(
FutureOr< void> onSubmit(Map<String, String> values), {bool resetOnSuccess = false}) → Future<bool> -
Validates, saves, and runs
onSubmitwith the current text values. -
submitValues(
FutureOr< void> onSubmit(GFormValues values), {bool resetOnSuccess = false}) → Future<bool> -
Validates, saves, and runs
onSubmitwith typed form values. -
text(
String name) → String -
Current text of the controller registered under
name. -
textController(
String name, {String? text}) → TextEditingController -
Returns the TextEditingController registered under
name, creating one withtextas its initial value if it doesn't exist yet. -
textValues(
) → Map< String, String> - Snapshot of every registered field's current text, keyed by name.
-
toString(
) → String -
A string representation of this object.
inherited
-
unfocus(
) → void - Drops focus from every field this controller owns.
-
unregister(
String name) → void -
Removes the field registered under
namefrom this controller. -
validate(
) → bool -
Runs every validator. Returns
trueif the form is valid. -
validateAndSave(
) → bool - Validates the form and, if valid, calls save. Returns whether the form was valid.
-
value<
T> (String name) → T? - Reads a typed field value.
-
values(
) → GFormValues - Snapshot of every registered typed value.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited