TextSuperFormField constructor

TextSuperFormField({
  1. Key? key,
  2. required String name,
  3. List<SuperFormFieldRule>? rules,
  4. InputDecoration? decoration = const InputDecoration(),
  5. TextInputType? keyboardType,
  6. TextCapitalization textCapitalization = TextCapitalization.none,
  7. TextInputAction? textInputAction,
  8. TextStyle? style,
  9. StrutStyle? strutStyle,
  10. TextDirection? textDirection,
  11. TextAlign textAlign = TextAlign.start,
  12. TextAlignVertical? textAlignVertical,
  13. bool autofocus = false,
  14. bool readOnly = false,
  15. ToolbarOptions? toolbarOptions,
  16. bool? showCursor,
  17. String obscuringCharacter = '•',
  18. bool obscureText = false,
  19. bool autocorrect = true,
  20. SmartDashesType? smartDashesType,
  21. SmartQuotesType? smartQuotesType,
  22. bool enableSuggestions = true,
  23. MaxLengthEnforcement? maxLengthEnforcement,
  24. int? maxLines = 1,
  25. int? minLines,
  26. bool expands = false,
  27. int? maxLength,
  28. ValueChanged<String>? onChanged,
  29. GestureTapCallback? onTap,
  30. VoidCallback? onEditingComplete,
  31. ValueChanged<String>? onFieldSubmitted,
  32. List<TextInputFormatter>? inputFormatters,
  33. bool? enabled,
  34. double cursorWidth = 2.0,
  35. double? cursorHeight,
  36. Radius? cursorRadius,
  37. Color? cursorColor,
  38. Brightness? keyboardAppearance,
  39. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  40. bool enableInteractiveSelection = true,
  41. TextSelectionControls? selectionControls,
  42. InputCounterWidgetBuilder? buildCounter,
  43. ScrollPhysics? scrollPhysics,
  44. Iterable<String>? autofillHints,
  45. ScrollController? scrollController,
  46. Widget? noFormFallback,
  47. FocusNode? focusNode,
})

Implementation

TextSuperFormField({
  Key? key,
  required String name,
  List<SuperFormFieldRule>? rules,
  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,
  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,
  List<TextInputFormatter>? inputFormatters,
  bool? enabled,
  double cursorWidth = 2.0,
  double? cursorHeight,
  Radius? cursorRadius,
  Color? cursorColor,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool enableInteractiveSelection = true,
  TextSelectionControls? selectionControls,
  InputCounterWidgetBuilder? buildCounter,
  ScrollPhysics? scrollPhysics,
  Iterable<String>? autofillHints,
  ScrollController? scrollController,
  Widget? noFormFallback,
  FocusNode? focusNode,
}) : super(
        key: key,
        name: name,
        rules: rules ?? const [],
        noFormFallback: noFormFallback ?? const SizedBox(),
        focusNode: focusNode,
        builder: (
          BuildContext context,
          fieldState,
          formState,
        ) {
          fieldState as _TextSuperFormFieldState;
          final fieldData = formState.data[name];

          InputDecoration? effectiveDecoration =
              decoration ?? const InputDecoration();
          if (fieldData != null && fieldData.errors.isNotEmpty) {
            effectiveDecoration = effectiveDecoration.copyWith(
                errorText: fieldData.errors.first.message);
          }

          VoidCallback? effectiveOnEditingComplete = onEditingComplete;
          if (fieldData != null &&
              formState.validationMode == ValidationMode.onBlur) {
            effectiveOnEditingComplete = () {
              if (onEditingComplete != null) {
                onEditingComplete();
              }

              final validated = fieldData.validate(rules ?? []);
              if (validated.errors.isEmpty) {
                fieldState.focusNode.nextFocus();
              }

              formState.updateFieldData(validated);
            };
          }

          final effectiveEnabled = enabled ?? formState.enabled;

          return TextField(
            controller: fieldState._controller,
            focusNode: fieldState.focusNode,
            decoration: effectiveDecoration,
            keyboardType: keyboardType,
            textInputAction: textInputAction,
            style: style,
            strutStyle: strutStyle,
            textAlign: textAlign,
            textAlignVertical: textAlignVertical,
            textDirection: textDirection,
            textCapitalization: textCapitalization,
            autofocus: autofocus,
            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: onChanged,
            onTap: onTap,
            onEditingComplete: effectiveOnEditingComplete,
            onSubmitted: onFieldSubmitted,
            inputFormatters: inputFormatters,
            enabled: effectiveEnabled,
            cursorWidth: cursorWidth,
            cursorHeight: cursorHeight,
            cursorRadius: cursorRadius,
            cursorColor: cursorColor,
            scrollPadding: scrollPadding,
            scrollPhysics: scrollPhysics,
            keyboardAppearance: keyboardAppearance,
            enableInteractiveSelection: enableInteractiveSelection,
            selectionControls: selectionControls,
            buildCounter: buildCounter,
            autofillHints: autofillHints,
            scrollController: scrollController,
          );
        },
      );