EditableText constructor

EditableText(
  1. {Key? key,
  2. required TextEditingController controller,
  3. required FocusNode focusNode,
  4. bool readOnly = false,
  5. String obscuringCharacter = '•',
  6. bool obscureText = false,
  7. bool autocorrect = true,
  8. SmartDashesType? smartDashesType,
  9. SmartQuotesType? smartQuotesType,
  10. bool enableSuggestions = true,
  11. required TextStyle style,
  12. StrutStyle? strutStyle,
  13. required Color cursorColor,
  14. required Color backgroundCursorColor,
  15. TextAlign textAlign = TextAlign.start,
  16. TextDirection? textDirection,
  17. Locale? locale,
  18. @Deprecated('Use textScaler instead. ' 'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. ' 'This feature was deprecated after v3.12.0-2.0.pre.') double? textScaleFactor,
  19. TextScaler? textScaler,
  20. int? maxLines = 1,
  21. int? minLines,
  22. bool expands = false,
  23. bool forceLine = true,
  24. TextHeightBehavior? textHeightBehavior,
  25. TextWidthBasis textWidthBasis = TextWidthBasis.parent,
  26. bool autofocus = false,
  27. bool? showCursor,
  28. bool showSelectionHandles = false,
  29. Color? selectionColor,
  30. TextSelectionControls? selectionControls,
  31. TextInputType? keyboardType,
  32. TextInputAction? textInputAction,
  33. TextCapitalization textCapitalization = TextCapitalization.none,
  34. ValueChanged<String>? onChanged,
  35. VoidCallback? onEditingComplete,
  36. ValueChanged<String>? onSubmitted,
  37. AppPrivateCommandCallback? onAppPrivateCommand,
  38. SelectionChangedCallback? onSelectionChanged,
  39. VoidCallback? onSelectionHandleTapped,
  40. TapRegionCallback? onTapOutside,
  41. List<TextInputFormatter>? inputFormatters,
  42. MouseCursor? mouseCursor,
  43. bool rendererIgnoresPointer = false,
  44. double cursorWidth = 2.0,
  45. double? cursorHeight,
  46. Radius? cursorRadius,
  47. bool cursorOpacityAnimates = false,
  48. Offset? cursorOffset,
  49. bool paintCursorAboveText = false,
  50. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  51. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  52. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  53. Brightness keyboardAppearance = Brightness.light,
  54. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  55. bool? enableInteractiveSelection,
  56. ScrollController? scrollController,
  57. ScrollPhysics? scrollPhysics,
  58. Color? autocorrectionTextRectColor,
  59. @Deprecated('Use `contextMenuBuilder` instead. ' 'This feature was deprecated after v3.3.0-0.5.pre.') ToolbarOptions? toolbarOptions,
  60. Iterable<String>? autofillHints = const <String>[],
  61. AutofillClient? autofillClient,
  62. Clip clipBehavior = Clip.hardEdge,
  63. String? restorationId,
  64. ScrollBehavior? scrollBehavior,
  65. bool scribbleEnabled = true,
  66. bool enableIMEPersonalizedLearning = true,
  67. ContentInsertionConfiguration? contentInsertionConfiguration,
  68. EditableTextContextMenuBuilder? contextMenuBuilder,
  69. SpellCheckConfiguration? spellCheckConfiguration,
  70. TextMagnifierConfiguration magnifierConfiguration = TextMagnifierConfiguration.disabled,
  71. UndoHistoryController? undoController}
)

Creates a basic text input control.

The maxLines property can be set to null to remove the restriction on the number of lines. By default, it is one, meaning this is a single-line text field. maxLines must be null or greater than zero.

If keyboardType is not set or is null, its value will be inferred from autofillHints, if autofillHints is not empty. Otherwise it defaults to TextInputType.text if maxLines is exactly one, and TextInputType.multiline if maxLines is null or greater than one.

The text cursor is not shown if showCursor is false or if showCursor is null (the default) and readOnly is true.

Implementation

EditableText({
  super.key,
  required this.controller,
  required this.focusNode,
  this.readOnly = false,
  this.obscuringCharacter = '•',
  this.obscureText = false,
  this.autocorrect = true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  this.enableSuggestions = true,
  required this.style,
  StrutStyle? strutStyle,
  required this.cursorColor,
  required this.backgroundCursorColor,
  this.textAlign = TextAlign.start,
  this.textDirection,
  this.locale,
  @Deprecated(
    'Use textScaler instead. '
    'Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. '
    'This feature was deprecated after v3.12.0-2.0.pre.',
  )
  this.textScaleFactor,
  this.textScaler,
  this.maxLines = 1,
  this.minLines,
  this.expands = false,
  this.forceLine = true,
  this.textHeightBehavior,
  this.textWidthBasis = TextWidthBasis.parent,
  this.autofocus = false,
  bool? showCursor,
  this.showSelectionHandles = false,
  this.selectionColor,
  this.selectionControls,
  TextInputType? keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.onChanged,
  this.onEditingComplete,
  this.onSubmitted,
  this.onAppPrivateCommand,
  this.onSelectionChanged,
  this.onSelectionHandleTapped,
  this.onTapOutside,
  List<TextInputFormatter>? inputFormatters,
  this.mouseCursor,
  this.rendererIgnoresPointer = false,
  this.cursorWidth = 2.0,
  this.cursorHeight,
  this.cursorRadius,
  this.cursorOpacityAnimates = false,
  this.cursorOffset,
  this.paintCursorAboveText = false,
  this.selectionHeightStyle = ui.BoxHeightStyle.tight,
  this.selectionWidthStyle = ui.BoxWidthStyle.tight,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.keyboardAppearance = Brightness.light,
  this.dragStartBehavior = DragStartBehavior.start,
  bool? enableInteractiveSelection,
  this.scrollController,
  this.scrollPhysics,
  this.autocorrectionTextRectColor,
  @Deprecated(
    'Use `contextMenuBuilder` instead. '
    'This feature was deprecated after v3.3.0-0.5.pre.',
  )
  ToolbarOptions? toolbarOptions,
  this.autofillHints = const <String>[],
  this.autofillClient,
  this.clipBehavior = Clip.hardEdge,
  this.restorationId,
  this.scrollBehavior,
  this.scribbleEnabled = true,
  this.enableIMEPersonalizedLearning = true,
  this.contentInsertionConfiguration,
  this.contextMenuBuilder,
  this.spellCheckConfiguration,
  this.magnifierConfiguration = TextMagnifierConfiguration.disabled,
  this.undoController,
}) : assert(obscuringCharacter.length == 1),
     smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
     smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
     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.'),
     enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText),
     toolbarOptions = selectionControls is TextSelectionHandleControls && toolbarOptions == null ? ToolbarOptions.empty : toolbarOptions ??
         (obscureText
             ? (readOnly
                 // No point in even offering "Select All" in a read-only obscured
                 // field.
                 ? ToolbarOptions.empty
                 // Writable, but obscured.
                 : const ToolbarOptions(
                     selectAll: true,
                     paste: true,
                   ))
             : (readOnly
                 // Read-only, not obscured.
                 ? const ToolbarOptions(
                     selectAll: true,
                     copy: true,
                   )
                 // Writable, not obscured.
                 : const ToolbarOptions(
                     copy: true,
                     cut: true,
                     selectAll: true,
                     paste: true,
                   ))),
     assert(
        spellCheckConfiguration == null ||
        spellCheckConfiguration == const SpellCheckConfiguration.disabled() ||
        spellCheckConfiguration.misspelledTextStyle != null,
        'spellCheckConfiguration must specify a misspelledTextStyle if spell check behavior is desired',
     ),
     _strutStyle = strutStyle,
     keyboardType = keyboardType ?? _inferKeyboardType(autofillHints: autofillHints, maxLines: maxLines),
     inputFormatters = maxLines == 1
         ? <TextInputFormatter>[
             FilteringTextInputFormatter.singleLineFormatter,
             ...inputFormatters ?? const Iterable<TextInputFormatter>.empty(),
           ]
         : inputFormatters,
     showCursor = showCursor ?? !readOnly;