TextFormBox constructor

TextFormBox({
  1. Key? key,
  2. TextEditingController? controller,
  3. String? initialValue,
  4. FocusNode? focusNode,
  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. bool? showCursor,
  16. String obscuringCharacter = '•',
  17. bool obscureText = false,
  18. bool autocorrect = true,
  19. SmartDashesType? smartDashesType,
  20. SmartQuotesType? smartQuotesType,
  21. bool enableSuggestions = true,
  22. int? maxLines = 1,
  23. int? minLines,
  24. bool expands = false,
  25. int? maxLength,
  26. EdgeInsetsGeometry padding = kTextBoxPadding,
  27. ValueChanged<String>? onChanged,
  28. GestureTapCallback? onTap,
  29. TapRegionCallback? onTapOutside,
  30. VoidCallback? onEditingComplete,
  31. ValueChanged<String>? onFieldSubmitted,
  32. FormFieldSetter<String>? onSaved,
  33. FormFieldValidator<String>? validator,
  34. List<TextInputFormatter>? inputFormatters,
  35. bool enabled = true,
  36. double cursorWidth = 2.0,
  37. double? cursorHeight,
  38. Radius cursorRadius = const Radius.circular(2.0),
  39. Color? cursorColor,
  40. Brightness? keyboardAppearance,
  41. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  42. bool? enableInteractiveSelection,
  43. TextSelectionControls? selectionControls,
  44. ScrollPhysics? scrollPhysics,
  45. Iterable<String>? autofillHints,
  46. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  47. String? placeholder,
  48. TextStyle? placeholderStyle,
  49. ScrollController? scrollController,
  50. Clip clipBehavior = Clip.antiAlias,
  51. Widget? prefix,
  52. OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
  53. Widget? suffix,
  54. OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
  55. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  56. String? restorationId,
  57. MaxLengthEnforcement? maxLengthEnforcement,
  58. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  59. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  60. BoxDecoration? decoration,
  61. bool enableIMEPersonalizedLearning = true,
  62. MouseCursor? mouseCursor,
  63. bool scribbleEnabled = true,
  64. Color? highlightColor,
  65. Color? errorHighlightColor,
  66. Color? unfocusedColor,
  67. EditableTextContextMenuBuilder? contextMenuBuilder,
  68. TextMagnifierConfiguration? magnifierConfiguration,
  69. SpellCheckConfiguration? spellCheckConfiguration,
})

Creates a FormField that contains a TextBox.

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 TextBox class and TextBox.new, the constructor.

Implementation

TextFormBox({
  super.key,
  super.controller,
  String? initialValue,
  FocusNode? focusNode,
  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,
  int? maxLines = 1,
  int? minLines,
  bool expands = false,
  int? maxLength,
  EdgeInsetsGeometry padding = kTextBoxPadding,
  ValueChanged<String>? onChanged,
  GestureTapCallback? onTap,
  TapRegionCallback? onTapOutside,
  VoidCallback? onEditingComplete,
  ValueChanged<String>? onFieldSubmitted,
  super.onSaved,
  super.validator,
  List<TextInputFormatter>? inputFormatters,
  super.enabled = true,
  double cursorWidth = 2.0,
  double? cursorHeight,
  Radius cursorRadius = const Radius.circular(2.0),
  Color? cursorColor,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool? enableInteractiveSelection,
  TextSelectionControls? selectionControls,
  ScrollPhysics? scrollPhysics,
  Iterable<String>? autofillHints,
  super.autovalidateMode = AutovalidateMode.disabled,
  String? placeholder,
  TextStyle? placeholderStyle,
  ScrollController? scrollController,
  Clip clipBehavior = Clip.antiAlias,
  Widget? prefix,
  OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
  Widget? suffix,
  OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
  DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  String? restorationId,
  MaxLengthEnforcement? maxLengthEnforcement,
  ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  BoxDecoration? decoration,
  bool enableIMEPersonalizedLearning = true,
  MouseCursor? mouseCursor,
  bool scribbleEnabled = true,
  Color? highlightColor,
  Color? errorHighlightColor,
  Color? unfocusedColor,
  EditableTextContextMenuBuilder? contextMenuBuilder,
  TextMagnifierConfiguration? magnifierConfiguration,
  SpellCheckConfiguration? spellCheckConfiguration,
})  : assert(initialValue == null || controller == null),
      assert(obscuringCharacter.length == 1),
      assert(maxLines == null || maxLines > 0),
      assert(minLines == null || minLines > 0),
      assert(
        (maxLines == null) || (minLines == null) || (maxLines >= minLines),
        "minLines can't be greater than maxLines",
      ),
      assert(
        !expands || (maxLines == null && minLines == null),
        'minLines and maxLines must be null when expands is true.',
      ),
      assert(!obscureText || maxLines == 1,
          'Obscured fields cannot be multiline.'),
      assert(maxLength == null || maxLength > 0),
      super(
        initialValue:
            controller != null ? controller.text : (initialValue ?? ''),
        builder: (FormFieldState<String> field) {
          assert(debugCheckHasFluentTheme(field.context));
          final theme = FluentTheme.of(field.context);
          final state = field as TextFormBoxState;

          void onChangedHandler(String value) {
            field.didChange(value);
            if (onChanged != null) {
              onChanged(value);
            }
          }

          return UnmanagedRestorationScope(
            bucket: field.bucket,
            child: FormRow(
              padding: EdgeInsets.zero,
              error:
                  (field.errorText == null) ? null : Text(field.errorText!),
              child: TextBox(
                controller: state._effectiveController,
                focusNode: focusNode,
                keyboardType: keyboardType,
                textInputAction: textInputAction,
                style: style,
                strutStyle: strutStyle,
                textAlign: textAlign,
                textAlignVertical: textAlignVertical,
                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,
                maxLines: maxLines,
                minLines: minLines,
                expands: expands,
                maxLength: maxLength,
                onChanged: onChangedHandler,
                onTap: onTap,
                onTapOutside: onTapOutside,
                onEditingComplete: onEditingComplete,
                onSubmitted: onFieldSubmitted,
                inputFormatters: inputFormatters,
                enabled: enabled,
                cursorWidth: cursorWidth,
                cursorHeight: cursorHeight,
                cursorColor: cursorColor,
                cursorRadius: cursorRadius,
                scrollPadding: scrollPadding,
                scrollPhysics: scrollPhysics,
                keyboardAppearance: keyboardAppearance,
                enableInteractiveSelection: enableInteractiveSelection,
                autofillHints: autofillHints,
                placeholder: placeholder,
                placeholderStyle: placeholderStyle,
                scrollController: scrollController,
                clipBehavior: clipBehavior,
                prefix: prefix,
                prefixMode: prefixMode,
                suffix: suffix,
                suffixMode: suffixMode,
                highlightColor: (field.errorText == null)
                    ? highlightColor
                    : errorHighlightColor ??
                        Colors.red.defaultBrushFor(theme.brightness),
                unfocusedColor: unfocusedColor,
                dragStartBehavior: dragStartBehavior,
                padding: padding,
                maxLengthEnforcement: maxLengthEnforcement,
                restorationId: restorationId,
                selectionHeightStyle: selectionHeightStyle,
                selectionWidthStyle: selectionWidthStyle,
                decoration: decoration,
                enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
                scribbleEnabled: scribbleEnabled,
                textDirection: textDirection,
                selectionControls: selectionControls,
                contextMenuBuilder: contextMenuBuilder,
                magnifierConfiguration: magnifierConfiguration,
                spellCheckConfiguration: spellCheckConfiguration,
              ),
            ),
          );
        },
      );