EditableText constructor Null safety
- {Key? key,
- required TextEditingController controller,
- required FocusNode focusNode,
- bool readOnly = false,
- String obscuringCharacter = '•',
- bool obscureText = false,
- bool autocorrect = true,
- SmartDashesType? smartDashesType,
- SmartQuotesType? smartQuotesType,
- bool enableSuggestions = true,
- required TextStyle style,
- StrutStyle? strutStyle,
- required Color cursorColor,
- required Color backgroundCursorColor,
- TextAlign textAlign = TextAlign.start,
- TextDirection? textDirection,
- Locale? locale,
- double? textScaleFactor,
- int? maxLines = 1,
- int? minLines,
- bool expands = false,
- bool forceLine = true,
- TextHeightBehavior? textHeightBehavior,
- TextWidthBasis textWidthBasis = TextWidthBasis.parent,
- bool autofocus = false,
- bool? showCursor,
- bool showSelectionHandles = false,
- Color? selectionColor,
- TextSelectionControls? selectionControls,
- TextInputType? keyboardType,
- TextInputAction? textInputAction,
- TextCapitalization textCapitalization = TextCapitalization.none,
- ValueChanged<
String> ? onChanged, - VoidCallback? onEditingComplete,
- ValueChanged<
String> ? onSubmitted, - AppPrivateCommandCallback? onAppPrivateCommand,
- SelectionChangedCallback? onSelectionChanged,
- VoidCallback? onSelectionHandleTapped,
- TapRegionCallback? onTapOutside,
- List<
TextInputFormatter> ? inputFormatters, - MouseCursor? mouseCursor,
- bool rendererIgnoresPointer = false,
- double cursorWidth = 2.0,
- double? cursorHeight,
- Radius? cursorRadius,
- bool cursorOpacityAnimates = false,
- Offset? cursorOffset,
- bool paintCursorAboveText = false,
- BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
- BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
- EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
- Brightness keyboardAppearance = Brightness.light,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- bool? enableInteractiveSelection,
- ScrollController? scrollController,
- ScrollPhysics? scrollPhysics,
- Color? autocorrectionTextRectColor,
- ToolbarOptions? toolbarOptions,
- Iterable<
String> ? autofillHints = const <String>[], - AutofillClient? autofillClient,
- Clip clipBehavior = Clip.hardEdge,
- String? restorationId,
- ScrollBehavior? scrollBehavior,
- bool scribbleEnabled = true,
- bool enableIMEPersonalizedLearning = true}
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.
The controller, focusNode, obscureText, autocorrect, autofocus,
showSelectionHandles, enableInteractiveSelection
, forceLine,
style, cursorColor, cursorOpacityAnimates,backgroundCursorColor,
enableSuggestions, paintCursorAboveText, selectionHeightStyle,
selectionWidthStyle, textAlign, dragStartBehavior, scrollPadding,
dragStartBehavior, toolbarOptions
, rendererIgnoresPointer,
readOnly, and enableIMEPersonalizedLearning arguments must not be null.
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,
this.textScaleFactor,
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,
ToolbarOptions? toolbarOptions,
this.autofillHints = const <String>[],
this.autofillClient,
this.clipBehavior = Clip.hardEdge,
this.restorationId,
this.scrollBehavior,
this.scribbleEnabled = true,
this.enableIMEPersonalizedLearning = true,
}) : assert(controller != null),
assert(focusNode != null),
assert(obscuringCharacter != null && obscuringCharacter.length == 1),
assert(obscureText != null),
assert(autocorrect != null),
smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
assert(enableSuggestions != null),
assert(showSelectionHandles != null),
assert(readOnly != null),
assert(forceLine != null),
assert(style != null),
assert(cursorColor != null),
assert(cursorOpacityAnimates != null),
assert(paintCursorAboveText != null),
assert(backgroundCursorColor != null),
assert(selectionHeightStyle != null),
assert(selectionWidthStyle != null),
assert(textAlign != null),
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 != null),
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(autofocus != null),
assert(rendererIgnoresPointer != null),
assert(scrollPadding != null),
assert(dragStartBehavior != null),
enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText),
toolbarOptions = toolbarOptions ??
(obscureText
? (readOnly
// No point in even offering "Select All" in a read-only obscured
// field.
? const ToolbarOptions()
// 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(clipBehavior != null),
assert(enableIMEPersonalizedLearning != null),
_strutStyle = strutStyle,
keyboardType = keyboardType ?? _inferKeyboardType(autofillHints: autofillHints, maxLines: maxLines),
inputFormatters = maxLines == 1
? <TextInputFormatter>[
FilteringTextInputFormatter.singleLineFormatter,
...inputFormatters ?? const Iterable<TextInputFormatter>.empty(),
]
: inputFormatters,
showCursor = showCursor ?? !readOnly;