WellFormed.btn constructor

WellFormed.btn(
  1. List<Widget> fields, {
  2. bool enabled = true,
  3. bool hasReset = true,
  4. Widget submitChild = const Text('Submit'),
  5. Widget resetChild = const Text('Reset'),
  6. Widget? leading,
  7. ButtonStyle? submitStyle,
  8. ButtonStyle? resetStyle,
  9. VoidCallback? onSub,
  10. VoidCallback? onReset,
  11. Axis scrollDirection = Axis.vertical,
  12. GlobalKey<FormState>? formKey,
  13. Key? submitKey,
  14. Key? resetKey,
  15. Key? key,
})

Convenient Scrollable Form Widget that contains a ElevatedButton for submission along with an optional reset TextButtonfor resetting all form fields back to their FormField.initialValue.

fields the Form's fields. enabled enable/disable flag. hasReset if true, the form will have a reset button. submitChild the child widget of the submission button. resetChild the child widget of the reset button. leading if set, an extra widget will be placed on the leftmost position alongside the submission and reset buttons. scrollDirection the axis along which the scroll view scrolls. formKey the form state key; if omitted, one will be generated. submitKey the submit button key — it might be useful for unit testing. resetKey the reset button key — it might be useful for unit testing.

Implementation

WellFormed.btn(
  List<Widget> fields, {
  bool enabled = true,
  bool hasReset = true,
  Widget submitChild = const Text('Submit'),
  Widget resetChild = const Text('Reset'),
  Widget? leading,
  ButtonStyle? submitStyle,
  ButtonStyle? resetStyle,
  VoidCallback? onSub,
  VoidCallback? onReset,
  Axis scrollDirection = Axis.vertical,
  GlobalKey<FormState>? formKey,
  Key? submitKey,
  Key? resetKey,
  Key? key,
}) : this.scroll(
        fields,
        scrollDirection: scrollDirection,
        submit: (VoidCallback submit) {
          return ElevatedButton(
            key: submitKey,
            style: submitStyle,
            onPressed: !enabled
                ? null
                : () {
                    submit();
                    onSub?.call();
                  },
            child: submitChild,
          );
        },
        reset: (VoidCallback reset) {
          return !hasReset
              ? const SizedBox()
              : TextButton(
                  key: resetKey,
                  style: resetStyle,
                  onPressed: !enabled
                      ? null
                      : () {
                          reset();
                          onReset?.call();
                        },
                  child: resetChild,
                );
        },
        leading: leading,
        formKey: formKey,
        key: key,
      );