PlatformText constructor

const PlatformText(
  1. String data, {
  2. Key? key,
  3. TextStyle? style,
  4. StrutStyle? strutStyle,
  5. TextAlign? textAlign,
  6. TextDirection? textDirection,
  7. double? textScaleFactor,
  8. int? maxLines,
  9. String? semanticsLabel,
  10. TextHeightBehavior? textHeightBehavior,
  11. TextWidthBasis? textWidthBasis,
  12. Locale? locale,
  13. bool? softWrap,
  14. TextOverflow? overflow,
  15. FocusNode? focusNode,
  16. bool showCursor = false,
  17. bool autofocus = false,
  18. ToolbarOptions? toolbarOptions,
  19. int? minLines,
  20. double cursorWidth = 2.0,
  21. double? cursorHeight,
  22. Radius? cursorRadius,
  23. Color? cursorColor,
  24. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  25. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  26. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  27. bool enableInteractiveSelection = true,
  28. TextSelectionControls? selectionControls,
  29. GestureTapCallback? onTap,
  30. ScrollPhysics? scrollPhysics,
  31. SelectionChangedCallback? onSelectionChanged,
  32. @visibleForTesting bool webTest = false,
})

Creates a PlatformText text widget.

Features

PlatformText returns Text or SelectableText widget depending on the platform it's running on.

Native → Text

Web → SelectableText

Usage

{@tool snippet}

Create a PlatformText widget.

PlatformText('Hello mom!');

{@end-tool}

Implementation

const PlatformText(
  String this.data, {
  Key? key,
  this.style,
  this.strutStyle,
  this.textAlign,
  this.textDirection,
  this.textScaleFactor,
  this.maxLines,
  this.semanticsLabel,
  this.textHeightBehavior,
  this.textWidthBasis,
  this.locale,
  this.softWrap,
  this.overflow,
  this.focusNode,
  this.showCursor = false,
  this.autofocus = false,
  ToolbarOptions? toolbarOptions,
  this.minLines,
  this.cursorWidth = 2.0,
  this.cursorHeight,
  this.cursorRadius,
  this.cursorColor,
  this.selectionHeightStyle = ui.BoxHeightStyle.tight,
  this.selectionWidthStyle = ui.BoxWidthStyle.tight,
  this.dragStartBehavior = DragStartBehavior.start,
  this.enableInteractiveSelection = true,
  this.selectionControls,
  this.onTap,
  this.scrollPhysics,
  this.onSelectionChanged,
  @visibleForTesting this.webTest = false,
})  : assert(maxLines == null || maxLines > 0),
      assert(minLines == null || minLines > 0),
      assert(
        (maxLines == null) || (minLines == null) || (maxLines >= minLines),
        "minLines can't be greater than maxLines",
      ),
      textSpan = null,
      toolbarOptions = toolbarOptions ??
          const ToolbarOptions(
            selectAll: true,
            copy: true,
          ),
      super(key: key);