SelectableText.rich constructor
const
SelectableText.rich(
- TextSpan textSpan, {
- Key? key,
- FocusNode? focusNode,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextAlign? textAlign,
- TextDirection? textDirection,
- TextScaler? textScaler,
- bool showCursor = false,
- bool autofocus = false,
- 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,
- bool useNativeContextMenu = false,
- EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder,
- TextMagnifierConfiguration? magnifierConfiguration,
Creates selectable text from a TextSpan for styled/rich text.
Use this constructor when you need to display text with multiple styles,
inline widgets, or complex formatting. The textSpan can contain nested
spans with different styles, colors, and even tap handlers.
Parameters are identical to the default constructor, except:
textSpan: The styled text span tree to display (required)- data is not available (use
textSpaninstead)
Example:
SelectableText.rich(
TextSpan(
text: 'Visit our ',
children: [
TextSpan(
text: 'website',
style: TextStyle(color: Colors.blue, decoration: TextDecoration.underline),
),
TextSpan(text: ' for more info'),
],
),
)
Implementation
const SelectableText.rich(
TextSpan this.textSpan, {
super.key,
this.focusNode,
this.style,
this.strutStyle,
this.textAlign,
this.textDirection,
this.textScaler,
this.showCursor = false,
this.autofocus = false,
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.useNativeContextMenu = false,
this.contextMenuBuilder = _defaultContextMenuBuilder,
this.magnifierConfiguration,
}) : 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;