PkForm class

A container widget that manages a group of fields validated by a PkObjectSchema.

Provides a PkFormController to the builder function; child widgets call PkFormController.setValue to register their values and PkFormController.submit to trigger validation and submission.

PkForm(
  schema: PkSchema.object({
    'email':    PkSchema.string().email().required(),
    'password': PkSchema.string().minLength(8).required(),
  }),
  onSubmit: (values) async {
    await authService.signIn(
      values['email'] as String,
      values['password'] as String,
    );
  },
  builder: (controller) => Column(
    children: [
      TextField(
        onChanged: (v) => controller.setValue('email', v),
        decoration: InputDecoration(
          labelText: 'Email',
          errorText: controller.errorFor('email'),
        ),
      ),
      TextField(
        obscureText: true,
        onChanged: (v) => controller.setValue('password', v),
        decoration: InputDecoration(
          labelText: 'Password',
          errorText: controller.errorFor('password'),
        ),
      ),
      ListenableBuilder(
        listenable: controller,
        builder: (_, __) => ElevatedButton(
          onPressed: controller.isSubmitting ? null : controller.submit,
          child: controller.isSubmitting
              ? const CircularProgressIndicator()
              : const Text('Sign in'),
        ),
      ),
    ],
  ),
)
Inheritance

Constructors

PkForm({Key? key, required PkObjectSchema schema, required Widget builder(PkFormController controller), required Future<void> onSubmit(Map<String, dynamic> values)})
const

Properties

builder Widget Function(PkFormController controller)
Builder that receives a PkFormController and returns the form UI.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onSubmit Future<void> Function(Map<String, dynamic> values)
Called with validated values when the form is submitted successfully.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
schema PkObjectSchema
The schema that defines validation rules for all fields.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<PkForm>
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