Skip to main content

SelectableText

Struct SelectableText 

Source
pub struct SelectableText {
Show 34 fields pub key: Option<KeyRef>, pub data: Option<String>, pub text_span: Option<TextSpan>, pub focus_node: Option<FocusNodeRef>, pub style: Option<TextStyle>, pub strut_style: Option<StrutStyle>, pub text_align: Option<TextAlign>, pub text_direction: Option<TextDirection>, pub text_scale_factor: Option<f64>, pub text_scaler: Option<TextScaler>, pub autofocus: bool, pub min_lines: Option<i32>, pub max_lines: Option<i32>, pub show_cursor: bool, pub cursor_width: f64, pub cursor_height: Option<f64>, pub cursor_radius: Option<Radius>, pub cursor_color: Option<Color>, pub selection_color: Option<Color>, pub selection_height_style: Option<BoxHeightStyle>, pub selection_width_style: Option<BoxWidthStyle>, pub enable_interactive_selection: bool, pub selection_controls: Option<Rc<dyn TextSelectionControls>>, pub drag_start_behavior: DragStartBehavior, pub toolbar_options: Option<ToolbarOptions>, pub on_tap: Option<GestureTapCallback>, pub scroll_physics: Option<ScrollPhysicsRef>, pub scroll_behavior: Option<ScrollBehaviorRef>, pub semantics_label: Option<String>, pub text_height_behavior: Option<TextHeightBehavior>, pub text_width_basis: Option<TextWidthBasis>, pub on_selection_changed: Option<SelectionChangedCallback>, pub context_menu_builder: Option<EditableTextContextMenuBuilder>, pub magnifier_configuration: Option<TextMagnifierConfiguration>,
}
Expand description

A run of selectable text with a single style.

Selectable text can’t receive keyboard focus by traversal: its focus node skips traversal.

The SelectableText widget displays a string of text with a single style. The string might break across multiple lines or might all be displayed on the same line depending on the layout constraints.

The style argument is optional. When omitted, the text will use the style from the closest enclosing DefaultTextStyle. If the given style’s TextStyle::inherit property is true (the default), the given style will be merged with the closest enclosing DefaultTextStyle. This merging behavior is useful, for example, to make the text bold while using the default font family and size.

SelectableText::rich shows text with several styles, as a TextSpan.

To make SelectableText react to touch events, use callback on_tap to achieve the desired behavior.

See also:

  • Text, which is the non selectable version of this widget.
  • TextField, which is the editable version of this widget.
  • SelectionArea, which enables the selection of multiple Text widgets and of other widgets.

Fields§

§key: Option<KeyRef>§data: Option<String>

The text to display.

This will be None if a text_span is provided instead.

§text_span: Option<TextSpan>

The text to display as a TextSpan.

This will be None if data is provided instead.

§focus_node: Option<FocusNodeRef>

Defines the focus for this widget.

Text is only selectable when widget is focused.

The focus_node is a long-lived object that’s typically managed by a StatefulWidget parent.

If null, this widget will create its own FocusNode with FocusNode::skip_traversal parameter set to true, which causes the widget to be skipped over during focus traversal.

§style: Option<TextStyle>

The style to use for the text.

If null, defaults to DefaultTextStyle of context.

§strut_style: Option<StrutStyle>

{@macro flutter.widgets.editableText.strutStyle}

§text_align: Option<TextAlign>

{@macro flutter.widgets.editableText.textAlign}

§text_direction: Option<TextDirection>

{@macro flutter.widgets.editableText.textDirection}

§text_scale_factor: Option<f64>
👎Deprecated:

Use text_scaler instead. Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. This feature was deprecated after v3.12.0-2.0.pre.

{@macro flutter.widgets.editableText.textScaleFactor}

§text_scaler: Option<TextScaler>

{@macro flutter.painting.textPainter.textScaler}

§autofocus: bool

{@macro flutter.widgets.editableText.autofocus}

§min_lines: Option<i32>

{@macro flutter.widgets.editableText.minLines}

§max_lines: Option<i32>

{@macro flutter.widgets.editableText.maxLines}

§show_cursor: bool

{@macro flutter.widgets.editableText.showCursor}

§cursor_width: f64

{@macro flutter.widgets.editableText.cursorWidth}

§cursor_height: Option<f64>

{@macro flutter.widgets.editableText.cursorHeight}

§cursor_radius: Option<Radius>

{@macro flutter.widgets.editableText.cursorRadius}

§cursor_color: Option<Color>

The color of the cursor.

The cursor indicates the current text insertion point.

If this is null it will default to DefaultSelectionStyle::cursor_color. If that is null, it will use CupertinoThemeData::primary_color on iOS and macOS, or ColorScheme::primary on other platforms.

§selection_color: Option<Color>

The color to use when painting the selection.

If this property is null, this widget gets the selection color from the DefaultSelectionStyle, or else a 40% opacity of the primary colour.

§selection_height_style: Option<BoxHeightStyle>

Controls how tall the selection highlight boxes are computed to be.

See BoxHeightStyle for details on available styles.

§selection_width_style: Option<BoxWidthStyle>

Controls how wide the selection highlight boxes are computed to be.

See BoxWidthStyle for details on available styles.

§enable_interactive_selection: bool

{@macro flutter.widgets.editableText.enableInteractiveSelection}

§selection_controls: Option<Rc<dyn TextSelectionControls>>

{@macro flutter.widgets.editableText.selectionControls}

§drag_start_behavior: DragStartBehavior

{@macro flutter.widgets.scrollable.dragStartBehavior}

§toolbar_options: Option<ToolbarOptions>
👎Deprecated:

Use context_menu_builder instead. This feature was deprecated after v3.3.0-0.5.pre.

Configuration of toolbar options.

Paste and cut will be disabled regardless.

If not set, select all and copy will be enabled by default.

§on_tap: Option<GestureTapCallback>

Called when the user taps on this selectable text.

The selectable text builds a GestureDetector to handle input events like tap, to trigger focus requests, to move the caret, adjust the selection, etc. Handling some of those events by wrapping the selectable text with a competing GestureDetector is problematic.

To unconditionally handle taps, without interfering with the selectable text’s internal gesture detector, provide this callback.

To be notified when the text field gains or loses the focus, provide a focus_node and add a listener to that.

To listen to arbitrary pointer events without competing with the selectable text’s internal gesture detector, use a Listener.

§scroll_physics: Option<ScrollPhysicsRef>

{@macro flutter.widgets.editableText.scrollPhysics}

§scroll_behavior: Option<ScrollBehaviorRef>

{@macro flutter.widgets.editableText.scrollBehavior}

§semantics_label: Option<String>

{@macro flutter.widgets.Text.semanticsLabel}

§text_height_behavior: Option<TextHeightBehavior>

{@macro dart.ui.textHeightBehavior}

§text_width_basis: Option<TextWidthBasis>

{@macro flutter.painting.textPainter.textWidthBasis}

§on_selection_changed: Option<SelectionChangedCallback>

{@macro flutter.widgets.editableText.onSelectionChanged}

§context_menu_builder: Option<EditableTextContextMenuBuilder>

{@macro flutter.widgets.EditableText.contextMenuBuilder}

§magnifier_configuration: Option<TextMagnifierConfiguration>

The configuration for the magnifier used when the text is selected.

By default, builds a CupertinoTextMagnifier on iOS and TextMagnifier on Android, and builds nothing on all other platforms. To suppress the magnifier, consider passing TextMagnifierConfiguration::DISABLED.

Implementations§

Source§

impl SelectableText

Source

pub fn new(data: impl Into<String>) -> SelectableText

Creates a selectable text widget.

If the style argument is null, the text will use the style from the closest enclosing DefaultTextStyle.

Source

pub fn rich(text_span: TextSpan) -> SelectableText

Creates a selectable text widget with a TextSpan.

The text_span parameter must not be null and only contain TextSpan in TextSpan::children. Other type of InlineSpan is not allowed.

Source

pub fn key(self, key: KeyRef) -> SelectableText

Dart SelectableText(key:).

Source

pub fn focus_node(self, focus_node: FocusNodeRef) -> SelectableText

Dart SelectableText(focusNode:).

Source

pub fn style(self, style: TextStyle) -> SelectableText

Dart SelectableText(style:).

Source

pub fn strut_style(self, strut_style: StrutStyle) -> SelectableText

Dart SelectableText(strutStyle:).

Source

pub fn text_align(self, text_align: TextAlign) -> SelectableText

Dart SelectableText(textAlign:).

Source

pub fn text_direction(self, text_direction: TextDirection) -> SelectableText

Dart SelectableText(textDirection:).

Source

pub fn text_scale_factor(self, text_scale_factor: f64) -> SelectableText

👎Deprecated:

Use text_scaler instead. Use of textScaleFactor was deprecated in preparation for the upcoming nonlinear text scaling support. This feature was deprecated after v3.12.0-2.0.pre.

Dart SelectableText(textScaleFactor:).

Source

pub fn text_scaler(self, text_scaler: TextScaler) -> SelectableText

Dart SelectableText(textScaler:).

Source

pub fn show_cursor(self, show_cursor: bool) -> SelectableText

Dart SelectableText(showCursor:).

Source

pub fn autofocus(self, autofocus: bool) -> SelectableText

Dart SelectableText(autofocus:).

Source

pub fn toolbar_options(self, toolbar_options: ToolbarOptions) -> SelectableText

👎Deprecated:

Use context_menu_builder instead. This feature was deprecated after v3.3.0-0.5.pre.

Dart SelectableText(toolbarOptions:).

Source

pub fn min_lines(self, min_lines: i32) -> SelectableText

Dart SelectableText(minLines:).

Source

pub fn max_lines(self, max_lines: Option<i32>) -> SelectableText

Dart SelectableText(maxLines:).

Source

pub fn cursor_width(self, cursor_width: f64) -> SelectableText

Dart SelectableText(cursorWidth:).

Source

pub fn cursor_height(self, cursor_height: f64) -> SelectableText

Dart SelectableText(cursorHeight:).

Source

pub fn cursor_radius(self, cursor_radius: Radius) -> SelectableText

Dart SelectableText(cursorRadius:).

Source

pub fn cursor_color(self, cursor_color: Color) -> SelectableText

Dart SelectableText(cursorColor:).

Source

pub fn selection_color(self, selection_color: Color) -> SelectableText

Dart SelectableText(selectionColor:).

Source

pub fn selection_height_style( self, selection_height_style: BoxHeightStyle, ) -> SelectableText

Dart SelectableText(selectionHeightStyle:).

Source

pub fn selection_width_style( self, selection_width_style: BoxWidthStyle, ) -> SelectableText

Dart SelectableText(selectionWidthStyle:).

Source

pub fn drag_start_behavior( self, drag_start_behavior: DragStartBehavior, ) -> SelectableText

Dart SelectableText(dragStartBehavior:).

Source

pub fn enable_interactive_selection( self, enable_interactive_selection: bool, ) -> SelectableText

Dart SelectableText(enableInteractiveSelection:).

Source

pub fn selection_controls( self, selection_controls: Rc<dyn TextSelectionControls>, ) -> SelectableText

Dart SelectableText(selectionControls:).

Source

pub fn on_tap(self, on_tap: GestureTapCallback) -> SelectableText

Dart SelectableText(onTap:).

Source

pub fn scroll_physics(self, scroll_physics: ScrollPhysicsRef) -> SelectableText

Dart SelectableText(scrollPhysics:).

Source

pub fn scroll_behavior( self, scroll_behavior: ScrollBehaviorRef, ) -> SelectableText

Dart SelectableText(scrollBehavior:).

Source

pub fn semantics_label( self, semantics_label: impl Into<String>, ) -> SelectableText

Dart SelectableText(semanticsLabel:).

Source

pub fn text_height_behavior( self, text_height_behavior: TextHeightBehavior, ) -> SelectableText

Dart SelectableText(textHeightBehavior:).

Source

pub fn text_width_basis( self, text_width_basis: TextWidthBasis, ) -> SelectableText

Dart SelectableText(textWidthBasis:).

Source

pub fn on_selection_changed( self, on_selection_changed: impl Fn(&mut App, TextSelection, Option<SelectionChangedCause>) + 'static, ) -> SelectableText

Dart SelectableText(onSelectionChanged:).

Source

pub fn context_menu_builder( self, context_menu_builder: Option<EditableTextContextMenuBuilder>, ) -> SelectableText

Dart SelectableText(contextMenuBuilder:); None builds no context menu.

Source

pub fn magnifier_configuration( self, magnifier_configuration: TextMagnifierConfiguration, ) -> SelectableText

Dart SelectableText(magnifierConfiguration:).

Source

pub fn selection_enabled(&self) -> bool

{@macro flutter.widgets.editableText.selectionEnabled}

Trait Implementations§

Source§

impl Debug for SelectableText

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for SelectableText

Source§

type State = SelectableTextState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> SelectableTextState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for SelectableText

§

impl !Send for SelectableText

§

impl !Sync for SelectableText

§

impl !UnwindSafe for SelectableText

§

impl Forget for SelectableText

§

impl Freeze for SelectableText
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<Rc<dyn InlineSpan>>: Freeze, &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze, PhantomData<String>: Freeze, *const RcInner<Paint> is !null: Freeze, PhantomData<RcInner<Paint>>: Freeze, PhantomData<Shadow>: Freeze, PhantomData<FontFeature>: Freeze, PhantomData<FontVariation>: Freeze, NonZero<u32>: Freeze, &'static GestureRecognizerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn MouseCursor> is !null: Freeze, PhantomData<RcInner<dyn MouseCursor>>: Freeze, *const RcInner<dyn Fn(&mut App, PointerEnterEvent)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, PointerEnterEvent)>>: Freeze, *const RcInner<dyn Fn(&mut App, PointerExitEvent)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, PointerExitEvent)>>: Freeze, &'static FocusNodeVTable: Freeze, *const TextScaler is !null: Freeze, PhantomData<TextScaler>: Freeze, *const RcInner<dyn TextSelectionControls> is !null: Freeze, PhantomData<RcInner<dyn TextSelectionControls>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, *const (): Freeze, *const RcInner<dyn ScrollPhysics> is !null: Freeze, PhantomData<RcInner<dyn ScrollPhysics>>: Freeze, *const RcInner<dyn ScrollBehavior> is !null: Freeze, PhantomData<RcInner<dyn ScrollBehavior>>: Freeze, *const RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, Retained<Handle<MagnifierController>>, Retained<Handle<ValueNotifier<MagnifierInfo>>>) -> Option<Rc<dyn Widget>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Retained<Handle<MagnifierController>>, Retained<Handle<ValueNotifier<MagnifierInfo>>>) -> Option<Rc<dyn Widget>>>>: Freeze,

§

impl Move for SelectableText

§

impl Unpin for SelectableText
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, Rc<dyn InlineSpan>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, Rc<Paint>: Unpin, NonZero<u32>: Unpin, &'static GestureRecognizerVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn MouseCursor>: Unpin, Rc<dyn Fn(&mut App, PointerEnterEvent)>: Unpin, Rc<dyn Fn(&mut App, PointerExitEvent)>: Unpin, &'static FocusNodeVTable: Unpin, Box<TextScaler>: Unpin, Rc<dyn TextSelectionControls>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, *const (): Unpin, Rc<dyn ScrollPhysics>: Unpin, Rc<dyn ScrollBehavior>: Unpin, Rc<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)>: Unpin, Rc<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&mut App, AnyElement, Retained<Handle<MagnifierController>>, Retained<Handle<ValueNotifier<MagnifierInfo>>>) -> Option<Rc<dyn Widget>>>: Unpin,

§

impl UnsafeUnpin for SelectableText
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<Rc<dyn InlineSpan>>: UnsafeUnpin, &'static dyn ColorExtension: UnsafeUnpin, *const RcInner<dyn ColorExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const RcInner<Paint> is !null: UnsafeUnpin, PhantomData<RcInner<Paint>>: UnsafeUnpin, PhantomData<Shadow>: UnsafeUnpin, PhantomData<FontFeature>: UnsafeUnpin, PhantomData<FontVariation>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static GestureRecognizerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn MouseCursor> is !null: UnsafeUnpin, PhantomData<RcInner<dyn MouseCursor>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, PointerEnterEvent)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, PointerEnterEvent)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, PointerExitEvent)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, PointerExitEvent)>>: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const TextScaler is !null: UnsafeUnpin, PhantomData<TextScaler>: UnsafeUnpin, *const RcInner<dyn TextSelectionControls> is !null: UnsafeUnpin, PhantomData<RcInner<dyn TextSelectionControls>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, *const (): UnsafeUnpin, *const RcInner<dyn ScrollPhysics> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ScrollPhysics>>: UnsafeUnpin, *const RcInner<dyn ScrollBehavior> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ScrollBehavior>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, TextSelection, Option<SelectionChangedCause>)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Handle<EditableTextState>) -> Rc<dyn Widget>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, Retained<Handle<MagnifierController>>, Retained<Handle<ValueNotifier<MagnifierInfo>>>) -> Option<Rc<dyn Widget>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, Retained<Handle<MagnifierController>>, Retained<Handle<ValueNotifier<MagnifierInfo>>>) -> Option<Rc<dyn Widget>>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>