EasyTextFormField constructor

EasyTextFormField({
  1. Key? key,
  2. required String name,
  3. TextEditingController? controller,
  4. String? initialValue,
  5. FocusNode? focusNode,
  6. InputDecoration decoration = const InputDecoration(),
  7. TextInputType? keyboardType,
  8. TextCapitalization textCapitalization = TextCapitalization.none,
  9. TextInputAction? textInputAction,
  10. TextStyle? style,
  11. StrutStyle? strutStyle,
  12. TextDirection? textDirection,
  13. TextAlign textAlign = TextAlign.start,
  14. TextAlignVertical? textAlignVertical,
  15. bool autofocus = false,
  16. bool readOnly = false,
  17. @Deprecated('Use `contextMenuBuilder` instead.') ToolbarOptions? toolbarOptions,
  18. bool? showCursor,
  19. String obscuringCharacter = '•',
  20. bool obscureText = false,
  21. bool autocorrect = true,
  22. SmartDashesType? smartDashesType,
  23. SmartQuotesType? smartQuotesType,
  24. bool enableSuggestions = true,
  25. MaxLengthEnforcement? maxLengthEnforcement,
  26. int maxLines = 1,
  27. int? minLines,
  28. bool expands = false,
  29. int? maxLength,
  30. ValueChanged<String>? onChanged,
  31. GestureTapCallback? onTap,
  32. VoidCallback? onEditingComplete,
  33. ValueChanged<String>? onFieldSubmitted,
  34. FormFieldSetter<String>? onSaved,
  35. EasyFormFieldValidator<String?>? validator,
  36. List<TextInputFormatter>? inputFormatters,
  37. bool enabled = true,
  38. double cursorWidth = 2.0,
  39. double? cursorHeight,
  40. Radius? cursorRadius,
  41. Color? cursorColor,
  42. Brightness? keyboardAppearance,
  43. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  44. bool enableInteractiveSelection = true,
  45. InputCounterWidgetBuilder? buildCounter,
  46. ScrollPhysics? scrollPhysics,
  47. Iterable<String>? autofillHints,
  48. ContentInsertionConfiguration? contentInsertionConfiguration,
  49. Clip clipBehavior = Clip.hardEdge,
  50. String? restorationId,
  51. bool scribbleEnabled = true,
  52. bool enableIMEPersonalizedLearning = true,
  53. EditableTextContextMenuBuilder? contextMenuBuilder,
  54. bool canRequestFocus = true,
  55. SpellCheckConfiguration? spellCheckConfiguration,
  56. TextMagnifierConfiguration? magnifierConfiguration,
  57. EasyAutovalidateMode autovalidateMode = EasyAutovalidateMode.disabled,
  58. bool saveOnSubmit = false,
})

Creates a EasyCustomFormField that contains a TextField.

When a controller is specified, initialValue must be null (the default). If controller is null, then a TextEditingController will be constructed automatically and its text will be initialized to initialValue or the empty string.

For documentation about the various parameters, see the TextField class and TextField, the constructor.

Implementation

EasyTextFormField({
  Key? key,
  required String name,
  TextEditingController? controller,
  String? initialValue,
  FocusNode? focusNode,
  InputDecoration decoration = const InputDecoration(),
  TextInputType? keyboardType,
  TextCapitalization textCapitalization = TextCapitalization.none,
  TextInputAction? textInputAction,
  TextStyle? style,
  StrutStyle? strutStyle,
  TextDirection? textDirection,
  TextAlign textAlign = TextAlign.start,
  TextAlignVertical? textAlignVertical,
  bool autofocus = false,
  bool readOnly = false,
  @Deprecated('Use `contextMenuBuilder` instead.')
  ToolbarOptions? toolbarOptions,
  bool? showCursor,
  String obscuringCharacter = '•',
  bool obscureText = false,
  bool autocorrect = true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  bool enableSuggestions = true,
  MaxLengthEnforcement? maxLengthEnforcement,
  int maxLines = 1,
  int? minLines,
  bool expands = false,
  int? maxLength,
  ValueChanged<String>? onChanged,
  GestureTapCallback? onTap,
  VoidCallback? onEditingComplete,
  ValueChanged<String>? onFieldSubmitted,
  FormFieldSetter<String>? onSaved,
  EasyFormFieldValidator<String?>? validator,
  List<TextInputFormatter>? inputFormatters,
  bool enabled = true,
  double cursorWidth = 2.0,
  double? cursorHeight,
  Radius? cursorRadius,
  Color? cursorColor,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool enableInteractiveSelection = true,
  InputCounterWidgetBuilder? buildCounter,
  ScrollPhysics? scrollPhysics,
  Iterable<String>? autofillHints,
  ContentInsertionConfiguration? contentInsertionConfiguration,
  Clip clipBehavior = Clip.hardEdge,
  String? restorationId,
  bool scribbleEnabled = true,
  bool enableIMEPersonalizedLearning = true,
  EditableTextContextMenuBuilder? contextMenuBuilder,
  bool canRequestFocus = true,
  SpellCheckConfiguration? spellCheckConfiguration,
  TextMagnifierConfiguration? magnifierConfiguration,
  EasyAutovalidateMode autovalidateMode = EasyAutovalidateMode.disabled,
  bool saveOnSubmit = false,
}) : super(
        key: key,
        name: name,
        controller: controller,
        focusNode: focusNode,
        initialValue: initialValue ?? '',
        controllerBuilder: (value) => TextEditingController(text: value),
        controllerRebuilder: (oldController) =>
            TextEditingController.fromValue(oldController.value),
        valueGet: (controller) => controller.text,
        valueSet: (controller, value) => controller.text = value ?? '',
        builder: (state, onChangedHandler) {
          final InputDecoration effectiveDecoration = decoration
              .applyDefaults(Theme.of(state.context).inputDecorationTheme);
          return TextField(
            controller: state.controller as TextEditingController?,
            focusNode: state.focusNode,
            decoration:
                effectiveDecoration.copyWith(errorText: state.errorText),
            keyboardType: keyboardType,
            textInputAction: textInputAction,
            style: style,
            strutStyle: strutStyle,
            textAlign: textAlign,
            textAlignVertical: textAlignVertical,
            textDirection: textDirection,
            textCapitalization: textCapitalization,
            autofocus: autofocus,
            // ignore: deprecated_member_use
            toolbarOptions: toolbarOptions,
            readOnly: readOnly,
            showCursor: showCursor,
            obscuringCharacter: obscuringCharacter,
            obscureText: obscureText,
            autocorrect: autocorrect,
            smartDashesType: smartDashesType ??
                (obscureText
                    ? SmartDashesType.disabled
                    : SmartDashesType.enabled),
            smartQuotesType: smartQuotesType ??
                (obscureText
                    ? SmartQuotesType.disabled
                    : SmartQuotesType.enabled),
            enableSuggestions: enableSuggestions,
            maxLengthEnforcement: maxLengthEnforcement,
            maxLines: maxLines,
            minLines: minLines,
            expands: expands,
            maxLength: maxLength,
            onChanged: onChangedHandler,
            onTap: onTap,
            onEditingComplete: onEditingComplete,
            onSubmitted: (value) {
              onFieldSubmitted?.call(value);
              if (saveOnSubmit) state.saveForm();
            },
            inputFormatters: inputFormatters,
            enabled: enabled,
            cursorWidth: cursorWidth,
            cursorHeight: cursorHeight,
            cursorRadius: cursorRadius,
            cursorColor: cursorColor,
            scrollPadding: scrollPadding,
            scrollPhysics: scrollPhysics,
            keyboardAppearance: keyboardAppearance,
            enableInteractiveSelection: enableInteractiveSelection,
            buildCounter: buildCounter,
            autofillHints: autofillHints,
            contentInsertionConfiguration: contentInsertionConfiguration,
            clipBehavior: clipBehavior,
            restorationId: restorationId,
            scribbleEnabled: scribbleEnabled,
            enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
            contextMenuBuilder: contextMenuBuilder,
            canRequestFocus: canRequestFocus,
            spellCheckConfiguration: spellCheckConfiguration,
            magnifierConfiguration: magnifierConfiguration,
          );
        },
        onChanged: onChanged,
        onSaved: onSaved,
        validator: validator,
        enabled: enabled,
        autovalidateMode: autovalidateMode,
      );