PlatformText.rich constructor
const
PlatformText.rich(
- TextSpan textSpan, {
- Key? key,
- FocusNode? focusNode,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextAlign? textAlign,
- TextDirection? textDirection,
- double? textScaleFactor,
- bool showCursor = false,
- bool autofocus = false,
- ToolbarOptions? toolbarOptions,
- int? minLines,
- int? maxLines,
- double cursorWidth = 2.0,
- double? cursorHeight,
- Radius? cursorRadius,
- Color? cursorColor,
- BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
- BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- bool enableInteractiveSelection = true,
- TextSelectionControls? selectionControls,
- GestureTapCallback? onTap,
- ScrollPhysics? scrollPhysics,
- String? semanticsLabel,
- TextHeightBehavior? textHeightBehavior,
- TextWidthBasis? textWidthBasis,
- SelectionChangedCallback? onSelectionChanged,
- Locale? locale,
- bool? softWrap,
- TextOverflow? overflow,
- @visibleForTesting bool webTest = false,
Creates a platform text widget with a InlineSpan.
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 with the InlineSpan.
PlatformText.rich(
TextSpan(
text: 'Hello',
children: <TextSpan>[
TextSpan(
text: ' beautiful ',
style: TextStyle(fontStyle: FontStyle.italic),
),
TextSpan(
text: 'mom!',
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
);
{@end-tool}
Implementation
const PlatformText.rich(
TextSpan this.textSpan, {
Key? key,
this.focusNode,
this.style,
this.strutStyle,
this.textAlign,
this.textDirection,
this.textScaleFactor,
this.showCursor = false,
this.autofocus = false,
ToolbarOptions? toolbarOptions,
this.minLines,
this.maxLines,
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.semanticsLabel,
this.textHeightBehavior,
this.textWidthBasis,
this.onSelectionChanged,
this.locale,
this.softWrap,
this.overflow,
@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",
),
data = null,
toolbarOptions = toolbarOptions ??
const ToolbarOptions(
selectAll: true,
copy: true,
),
super(key: key);