RenderEditable constructor Null safety

RenderEditable(
  1. {InlineSpan? text,
  2. required TextDirection textDirection,
  3. TextAlign textAlign = TextAlign.start,
  4. Color? cursorColor,
  5. Color? backgroundCursorColor,
  6. ValueNotifier<bool>? showCursor,
  7. bool? hasFocus,
  8. required LayerLink startHandleLayerLink,
  9. required LayerLink endHandleLayerLink,
  10. int? maxLines = 1,
  11. int? minLines,
  12. bool expands = false,
  13. StrutStyle? strutStyle,
  14. Color? selectionColor,
  15. double textScaleFactor = 1.0,
  16. TextSelection? selection,
  17. required ViewportOffset offset,
  18. @Deprecated('Uses the textSelectionDelegate.userUpdateTextEditingValue instead. ' 'This feature was deprecated after v1.26.0-17.2.pre.') SelectionChangedHandler? onSelectionChanged,
  19. CaretChangedHandler? onCaretChanged,
  20. bool ignorePointer,
  21. bool readOnly = false,
  22. bool forceLine = true,
  23. TextHeightBehavior? textHeightBehavior,
  24. TextWidthBasis textWidthBasis = TextWidthBasis.parent,
  25. String obscuringCharacter = '•',
  26. bool obscureText = false,
  27. Locale? locale,
  28. double cursorWidth = 1.0,
  29. double? cursorHeight,
  30. Radius? cursorRadius,
  31. bool paintCursorAboveText = false,
  32. Offset cursorOffset = Offset.zero,
  33. double devicePixelRatio = 1.0,
  34. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  35. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  36. bool? enableInteractiveSelection,
  37. EdgeInsets floatingCursorAddedMargin,
  38. TextRange? promptRectRange,
  39. Color? promptRectColor,
  40. Clip clipBehavior = Clip.hardEdge,
  41. required TextSelectionDelegate textSelectionDelegate,
  42. RenderEditablePainter? painter,
  43. RenderEditablePainter? foregroundPainter,
  44. List<RenderBox>? children}
)

Creates a render object that implements the visual aspects of a text field.

The textAlign argument must not be null. It defaults to TextAlign.start.

The textDirection argument must not be null.

If showCursor is not specified, then it defaults to hiding the cursor.

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

The offset is required and must not be null. You can use new ViewportOffset.zero if you have no need for scrolling.

Implementation

RenderEditable({
  InlineSpan? text,
  required TextDirection textDirection,
  TextAlign textAlign = TextAlign.start,
  Color? cursorColor,
  Color? backgroundCursorColor,
  ValueNotifier<bool>? showCursor,
  bool? hasFocus,
  required LayerLink startHandleLayerLink,
  required LayerLink endHandleLayerLink,
  int? maxLines = 1,
  int? minLines,
  bool expands = false,
  StrutStyle? strutStyle,
  Color? selectionColor,
  double textScaleFactor = 1.0,
  TextSelection? selection,
  required ViewportOffset offset,
  @Deprecated(
    'Uses the textSelectionDelegate.userUpdateTextEditingValue instead. '
    'This feature was deprecated after v1.26.0-17.2.pre.',
  )
  this.onSelectionChanged,
  this.onCaretChanged,
  this.ignorePointer = false,
  bool readOnly = false,
  bool forceLine = true,
  TextHeightBehavior? textHeightBehavior,
  TextWidthBasis textWidthBasis = TextWidthBasis.parent,
  String obscuringCharacter = '•',
  bool obscureText = false,
  Locale? locale,
  double cursorWidth = 1.0,
  double? cursorHeight,
  Radius? cursorRadius,
  bool paintCursorAboveText = false,
  Offset cursorOffset = Offset.zero,
  double devicePixelRatio = 1.0,
  ui.BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  ui.BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  bool? enableInteractiveSelection,
  this.floatingCursorAddedMargin = const EdgeInsets.fromLTRB(4, 4, 4, 5),
  TextRange? promptRectRange,
  Color? promptRectColor,
  Clip clipBehavior = Clip.hardEdge,
  required this.textSelectionDelegate,
  RenderEditablePainter? painter,
  RenderEditablePainter? foregroundPainter,
  List<RenderBox>? children,
}) : assert(textAlign != null),
     assert(textDirection != null, 'RenderEditable created without a textDirection.'),
     assert(maxLines == null || maxLines > 0),
     assert(minLines == null || minLines > 0),
     assert(startHandleLayerLink != null),
     assert(endHandleLayerLink != null),
     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(textScaleFactor != null),
     assert(offset != null),
     assert(ignorePointer != null),
     assert(textWidthBasis != null),
     assert(paintCursorAboveText != null),
     assert(obscuringCharacter != null && obscuringCharacter.characters.length == 1),
     assert(obscureText != null),
     assert(textSelectionDelegate != null),
     assert(cursorWidth != null && cursorWidth >= 0.0),
     assert(cursorHeight == null || cursorHeight >= 0.0),
     assert(readOnly != null),
     assert(forceLine != null),
     assert(devicePixelRatio != null),
     assert(selectionHeightStyle != null),
     assert(selectionWidthStyle != null),
     assert(clipBehavior != null),
     _textPainter = TextPainter(
       text: text,
       textAlign: textAlign,
       textDirection: textDirection,
       textScaleFactor: textScaleFactor,
       locale: locale,
       strutStyle: strutStyle,
       textHeightBehavior: textHeightBehavior,
       textWidthBasis: textWidthBasis,
     ),
     _showCursor = showCursor ?? ValueNotifier<bool>(false),
     _maxLines = maxLines,
     _minLines = minLines,
     _expands = expands,
     _selection = selection,
     _offset = offset,
     _cursorWidth = cursorWidth,
     _cursorHeight = cursorHeight,
     _paintCursorOnTop = paintCursorAboveText,
     _enableInteractiveSelection = enableInteractiveSelection,
     _devicePixelRatio = devicePixelRatio,
     _startHandleLayerLink = startHandleLayerLink,
     _endHandleLayerLink = endHandleLayerLink,
     _obscuringCharacter = obscuringCharacter,
     _obscureText = obscureText,
     _readOnly = readOnly,
     _forceLine = forceLine,
     _clipBehavior = clipBehavior,
     _hasFocus = hasFocus ?? false {
  assert(_showCursor != null);
  assert(!_showCursor.value || cursorColor != null);

  _selectionPainter.highlightColor = selectionColor;
  _selectionPainter.highlightedRange = selection;
  _selectionPainter.selectionHeightStyle = selectionHeightStyle;
  _selectionPainter.selectionWidthStyle = selectionWidthStyle;

  _autocorrectHighlightPainter.highlightColor = promptRectColor;
  _autocorrectHighlightPainter.highlightedRange = promptRectRange;

  _caretPainter.caretColor = cursorColor;
  _caretPainter.cursorRadius = cursorRadius;
  _caretPainter.cursorOffset = cursorOffset;
  _caretPainter.backgroundCursorColor = backgroundCursorColor;

  _updateForegroundPainter(foregroundPainter);
  _updatePainter(painter);
  addAll(children);
  _extractPlaceholderSpans(text);
}