FormController class

A controller to combine multible TextControllers and managing form satate.

{@tool snippet}

class _ExampleState extends State<Example> {

    late FormController _formController;

  void initState() {
    _formController = FormController();
    super.initState();
  }
  Form(
  key: _formController.key,
  child: Column(
    children: [
      const Text("field1"),
      TextFormField(
        //* Initialize controllers using a unique id!
        controller: _formController.controller("id1"),
      ),
      const Text("field2"),
      TextFormField(
        controller: _formController.controller("id2"),
      ),
      const Text("field3"),
      TextFormField(
        controller: _formController.controller("id3"),
      ),
      MaterialButton(
        onPressed: () {
          //* Get controller value
          _formController.value("id1")
          //* validate form
          _formController.validate()
          //* save form
          _formController.save()
          //* reset form
          _formController.reset()
        },
      ),
    ],
  ),
),

{@end-tool}

Constructors

FormController({Map<String, bool>? controllers})

Properties

controllers Map<String, bool>?
Specify the controllers' ids & their obscurity state to initialize at construction time.
final
hashCode int
The hash code for this object.
no setterinherited
key GlobalKey<FormState>
Use this key on the Form widget to get access to save,validate, and reset functions!
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

controller(String id, {String? initialText, bool isObscure = false}) TextEditingController
Use this function to supply a text field with the required controller,make sure to use a unique id!
dispose() Future<void>
Dispose of all StreamControllers.
isObscure(String id) bool
Use this function to get controller's obscurity value using the unique id you supplied earlier!
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Reset the current form state.
save() → void
Save the current form state.
set(String id, String text) → void
Use this function to set a text field value using the unique id you supplied earlier!
setObscurity(String id, bool isObscure) → void
Use this function to set controller's obscurity value using the unique id you supplied earlier!
submit({List<bool> extraValidators(Map<String, String>)?, dynamic onSuccess(Map<String, String> values)?}) → void
Submit the current form (Validate and return values).
toggleObscurity(String id) → void
Use this function to toggle controller's obscurity status using the unique id you supplied earlier!
toString() String
A string representation of this object.
inherited
validate() bool
Validate the current form state.
value(String id) String
Use this function to get a text field value using the unique id you supplied earlier!
valueStream(String id) Stream<String>
Use this function to stream a text field value using the unique id you supplied earlier!

Operators

operator ==(Object other) bool
The equality operator.
inherited