TextFormField constructor

TextFormField({
  1. Key? key,
  2. TextEditingController? controller,
  3. String? initialValue,
  4. FocusNode? focusNode,
  5. InputDecoration? decoration = const InputDecoration(),
  6. TextInputType? keyboardType,
  7. TextCapitalization textCapitalization = TextCapitalization.none,
  8. TextInputAction? textInputAction,
  9. TextStyle? style,
  10. StrutStyle? strutStyle,
  11. TextDirection? textDirection,
  12. TextAlign textAlign = TextAlign.start,
  13. TextAlignVertical? textAlignVertical,
  14. bool autofocus = false,
  15. bool readOnly = false,
  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. bool onTapAlwaysCalled = false,
  31. TapRegionCallback? onTapOutside,
  32. VoidCallback? onEditingComplete,
  33. ValueChanged<String>? onFieldSubmitted,
  34. FormFieldSetter<String>? onSaved,
  35. FormFieldValidator<String>? validator,
  36. FormFieldErrorBuilder? errorBuilder,
  37. List<TextInputFormatter>? inputFormatters,
  38. bool? enabled,
  39. double cursorWidth = 2,
  40. double? cursorHeight,
  41. Radius? cursorRadius,
  42. Color? cursorColor,
  43. Brightness? keyboardAppearance,
  44. EdgeInsets scrollPadding = const EdgeInsets.all(20),
  45. bool? enableInteractiveSelection,
  46. InputCounterWidgetBuilder? buildCounter,
  47. ScrollPhysics? scrollPhysics,
  48. Iterable<String>? autofillHints,
  49. AutovalidateMode? autovalidateMode,
  50. ScrollController? scrollController,
  51. MouseCursor? mouseCursor,
  52. EditableTextContextMenuBuilder? contextMenuBuilder = TextSelectionMenu.editableText,
  53. bool enableIMEPersonalizedLearning = true,
  54. bool canRequestFocus = true,
})

Implementation

TextFormField({
  super.key,
  this.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,
  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,
  this.onChanged,
  GestureTapCallback? onTap,
  bool onTapAlwaysCalled = false,
  TapRegionCallback? onTapOutside,
  VoidCallback? onEditingComplete,
  ValueChanged<String>? onFieldSubmitted,
  super.onSaved,
  super.validator,
  super.errorBuilder,
  List<TextInputFormatter>? inputFormatters,
  bool? enabled,
  double cursorWidth = 2,
  double? cursorHeight,
  Radius? cursorRadius,
  Color? cursorColor,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20),
  bool? enableInteractiveSelection,
  InputCounterWidgetBuilder? buildCounter,
  ScrollPhysics? scrollPhysics,
  Iterable<String>? autofillHints,
  AutovalidateMode? autovalidateMode,
  ScrollController? scrollController,
  MouseCursor? mouseCursor,
  EditableTextContextMenuBuilder? contextMenuBuilder =
      TextSelectionMenu.editableText,
  bool enableIMEPersonalizedLearning = true,
  bool canRequestFocus = true,
}) : super(
       initialValue: controller != null
           ? controller.text
           : (initialValue ?? ''),
       enabled: enabled ?? decoration?.enabled ?? true,
       autovalidateMode: autovalidateMode ?? AutovalidateMode.disabled,
       builder: (field) {
         final state = field as _TextFormFieldState;
         var effective = decoration ?? const InputDecoration();
         final errorText = field.errorText;
         if (errorText != null) {
           final errorBuilder = state.widget.errorBuilder;
           effective = errorBuilder != null
               ? effective.copyWith(
                   error: errorBuilder(state.context, errorText),
                 )
               : effective.copyWith(errorText: errorText);
         }
         return TextField(
           controller: state._effectiveController,
           focusNode: focusNode,
           decoration: effective,
           keyboardType: keyboardType,
           textInputAction: textInputAction,
           style: style,
           strutStyle: strutStyle,
           textAlign: textAlign,
           textAlignVertical: textAlignVertical,
           textDirection: textDirection,
           textCapitalization: textCapitalization,
           autofocus: autofocus,
           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: (value) {
             field.didChange(value);
             onChanged?.call(value);
           },
           onTap: onTap,
           onTapAlwaysCalled: onTapAlwaysCalled,
           onTapOutside: onTapOutside,
           onEditingComplete: onEditingComplete,
           onSubmitted: onFieldSubmitted,
           inputFormatters: inputFormatters,
           enabled: enabled ?? decoration?.enabled ?? true,
           cursorWidth: cursorWidth,
           cursorHeight: cursorHeight,
           cursorRadius: cursorRadius,
           cursorColor: cursorColor,
           scrollPadding: scrollPadding,
           scrollPhysics: scrollPhysics,
           keyboardAppearance: keyboardAppearance,
           enableInteractiveSelection:
               enableInteractiveSelection ?? (!obscureText || !readOnly),
           buildCounter: buildCounter,
           autofillHints: autofillHints,
           scrollController: scrollController,
           enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
           mouseCursor: mouseCursor,
           contextMenuBuilder: contextMenuBuilder,
           canRequestFocus: canRequestFocus,
         );
       },
     );