Skip to main content

Tooltip

Struct Tooltip 

Source
pub struct Tooltip {
Show 24 fields pub key: Option<KeyRef>, pub message: Option<String>, pub rich_message: Option<InlineSpanRef>, pub height: Option<f64>, pub constraints: Option<BoxConstraints>, pub padding: Option<EdgeInsetsGeometry>, pub margin: Option<EdgeInsetsGeometry>, pub vertical_offset: Option<f64>, pub prefer_below: Option<bool>, pub exclude_from_semantics: Option<bool>, pub child: Option<WidgetRef>, pub decoration: Option<DecorationRef>, pub text_style: Option<TextStyle>, pub text_align: Option<TextAlign>, pub wait_duration: Option<Duration>, pub show_duration: Option<Duration>, pub exit_duration: Option<Duration>, pub enable_tap_to_dismiss: bool, pub trigger_mode: Option<TooltipTriggerMode>, pub enable_feedback: Option<bool>, pub on_triggered: Option<TooltipTriggeredCallback>, pub mouse_cursor: Option<MouseCursorRef>, pub ignore_pointer: Option<bool>, pub position_delegate: Option<TooltipPositionDelegate>,
}
Expand description

A Material Design tooltip.

Tooltips provide text labels which help explain the function of a button or other user interface action. Wrap the button in a Tooltip widget and provide a message which will be shown when the widget is long pressed.

Many widgets, such as IconButton, FloatingActionButton, and PopupMenuButton have a tooltip property that, when non-null, causes the widget to include a Tooltip in its build.

Tooltips improve the accessibility of visual widgets by proving a textual representation of the widget, which, for example, can be vocalized by a screen reader.

This tooltip will default to showing above its child instead of below when its ambient TooltipThemeData::prefer_below is false. Setting that piece of theme data is recommended to avoid having a finger or cursor hide the tooltip. For other ways to set that piece of theme data see:

or it can be set directly on each tooltip with Tooltip::prefer_below.

A tooltip can be shown manually with TooltipTriggerMode::Manual by calling the TooltipState::ensure_tooltip_visible function.

See also:

Fields§

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

The text to display in the tooltip.

Only one of message and rich_message may be non-null.

§rich_message: Option<InlineSpanRef>

The rich text to display in the tooltip.

Only one of message and rich_message may be non-null.

§height: Option<f64>
👎Deprecated:

Use Tooltip.constraints instead. This feature was deprecated after v3.30.0-0.1.pre.

The minimum height of the Tooltip’s message.

§constraints: Option<BoxConstraints>

Constrains the size of the Tooltip’s message.

If null, then the TooltipThemeData::constraints of the ambient ThemeData::tooltip_theme will be used. If that is also null, then a default value will be picked based on the current platform. For desktop platforms, the default value is BoxConstraints(minHeight: 24.0), while for mobile platforms the default value is BoxConstraints(minHeight: 32.0).

§padding: Option<EdgeInsetsGeometry>

The amount of space by which to inset the Tooltip’s message.

On mobile, defaults to 16.0 logical pixels horizontally and 4.0 vertically. On desktop, defaults to 8.0 logical pixels horizontally and 4.0 vertically.

§margin: Option<EdgeInsetsGeometry>

The empty space that surrounds the tooltip.

Defines the tooltip’s outer Container::margin. By default, a long tooltip will span the width of its window. If long enough, a tooltip might also span the window’s height. This property allows one to define how much space the tooltip must be inset from the edges of their display window.

If this property is null, then TooltipThemeData::margin is used. If TooltipThemeData::margin is also null, the default margin is 0.0 logical pixels on all sides.

See also:

  • constraints, which allow setting an explicit size for the tooltip.
§vertical_offset: Option<f64>

The vertical gap between the widget and the displayed tooltip.

When prefer_below is set to true and tooltips have sufficient space to display themselves, this property defines how much vertical space tooltips will position themselves under their corresponding widgets. Otherwise, tooltips will position themselves above their corresponding widgets with the given offset.

§prefer_below: Option<bool>

Whether the tooltip defaults to being displayed below the widget.

If there is insufficient space to display the tooltip in the preferred direction, the tooltip will be displayed in the opposite direction.

If this property is null, then TooltipThemeData::prefer_below is used. If that is also null, the default value is true.

Applying TooltipThemeData::prefer_below: false for the entire app is recommended to avoid having a finger or cursor hide a tooltip.

§exclude_from_semantics: Option<bool>

Whether the tooltip’s message or rich_message should be excluded from the semantics tree.

Defaults to false. A tooltip will add a Semantics label that is set to Tooltip::message if non-null, or the plain text value of Tooltip::rich_message otherwise. Set this property to true if the app is going to provide its own custom semantics label.

§child: Option<WidgetRef>

The widget below this widget in the tree.

§decoration: Option<DecorationRef>

Specifies the tooltip’s shape and background color.

The tooltip shape defaults to a rounded rectangle with a border radius of 4.0. Tooltips will also default to an opacity of 90% and with the color Colors::GREY[700] if ThemeData::brightness is Brightness::Light, and Colors::WHITE if it is Brightness::Dark.

§text_style: Option<TextStyle>

The style to use for the message of the tooltip.

If null, the message’s TextStyle will be determined based on ThemeData. If ThemeData::brightness is set to Brightness::Dark, TextTheme::body_medium of ThemeData::text_theme will be used with Colors::WHITE. Otherwise, if ThemeData::brightness is set to Brightness::Light, TextTheme::body_medium of ThemeData::text_theme will be used with Colors::BLACK.

§text_align: Option<TextAlign>

How the message of the tooltip is aligned horizontally.

If this property is null, then TooltipThemeData::text_align is used. If TooltipThemeData::text_align is also null, the default value is TextAlign::Start.

§wait_duration: Option<Duration>

The length of time that a pointer must hover over a tooltip’s widget before the tooltip will be shown.

Defaults to 0 milliseconds (the tooltip is shown immediately upon hover).

§show_duration: Option<Duration>

The length of time that the tooltip will be shown after a long press is released (if trigger_mode is TooltipTriggerMode::LongPress) or a tap is released (if trigger_mode is TooltipTriggerMode::Tap).

This property does not affect mouse pointer devices.

Defaults to 1.5 seconds (the tooltip is shown 1.5 seconds after a tap or long press is released).

See also:

  • exit_duration, which allows configuring the time until a pointer disappears when hovering.
§exit_duration: Option<Duration>

The length of time that a pointer must have stopped hovering over a tooltip’s widget before the tooltip will be hidden.

Defaults to 100 milliseconds.

See also:

  • show_duration, which allows configuring the length of time that a tooltip will be visible after touch events are released.
§enable_tap_to_dismiss: bool

Whether the tooltip can be dismissed by tap.

The default value is true.

§trigger_mode: Option<TooltipTriggerMode>

The TooltipTriggerMode that will show the tooltip.

This property does not affect mouse devices. Setting trigger_mode to TooltipTriggerMode::Manual will not prevent the tooltip from showing when the mouse cursor hovers over it.

If this property is null, then TooltipThemeData::trigger_mode is used. If TooltipThemeData::trigger_mode is also null, the default mode is TooltipTriggerMode::LongPress.

§enable_feedback: Option<bool>

Whether the tooltip should provide acoustic and/or haptic feedback.

For example, on Android a tap will produce a clicking sound and a long-press will produce a short vibration, when feedback is enabled.

When null, the default value is true.

See also:

  • Feedback, for providing platform-specific feedback to certain actions.
§on_triggered: Option<TooltipTriggeredCallback>

Called when the Tooltip is triggered programmatically, on tap, or on long press.

The tooltip is triggered after a tap when trigger_mode is TooltipTriggerMode::Tap or after a long press when trigger_mode is TooltipTriggerMode::LongPress.

Hovering over the tooltip with a mouse pointer does not trigger this callback.

§mouse_cursor: Option<MouseCursorRef>

The cursor for a mouse pointer when it enters or is hovering over the widget.

If this property is null, MouseCursor::defer will be used.

§ignore_pointer: Option<bool>

Whether this tooltip should be invisible to hit testing.

If no value is passed, pointer events are ignored unless the tooltip has a rich_message instead of a message.

See also:

  • IgnorePointer, for more information about how pointer events are handled or ignored.
§position_delegate: Option<TooltipPositionDelegate>

A custom position delegate function for computing where the tooltip should be positioned.

If provided, this function will be called with a TooltipPositionContext containing all the necessary information for positioning the tooltip. The function should return an Offset indicating where to place the tooltip in the closest Overlay.

If null, defaults to positioning the tooltip center-aligned and below the target using position_dependent_box.

Implementations§

Source§

impl Tooltip

Source

pub fn new() -> Tooltip

Creates a tooltip.

By default, tooltips should adhere to the Material specification. If the optional constructor parameters are not defined, the values provided by TooltipTheme::of will be used if a TooltipTheme is present or specified in ThemeData.

All parameters that are defined in the constructor will override the default values and the values in TooltipTheme::of.

Exactly one of message and rich_message must be given; the tooltip’s state checks it when it builds.

Source

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

Dart Tooltip(key:).

Source

pub fn message(self, message: impl Into<String>) -> Tooltip

Dart Tooltip(message:).

Source

pub fn rich_message(self, rich_message: InlineSpanRef) -> Tooltip

Dart Tooltip(richMessage:).

Source

pub fn height(self, height: f64) -> Tooltip

👎Deprecated:

Use Tooltip.constraints instead. This feature was deprecated after v3.30.0-0.1.pre.

Dart Tooltip(height:).

Source

pub fn constraints(self, constraints: BoxConstraints) -> Tooltip

Dart Tooltip(constraints:).

Source

pub fn padding(self, padding: impl Into<EdgeInsetsGeometry>) -> Tooltip

Dart Tooltip(padding:).

Source

pub fn margin(self, margin: impl Into<EdgeInsetsGeometry>) -> Tooltip

Dart Tooltip(margin:).

Source

pub fn vertical_offset(self, vertical_offset: f64) -> Tooltip

Dart Tooltip(verticalOffset:).

Source

pub fn prefer_below(self, prefer_below: bool) -> Tooltip

Dart Tooltip(preferBelow:).

Source

pub fn exclude_from_semantics(self, exclude_from_semantics: bool) -> Tooltip

Dart Tooltip(excludeFromSemantics:).

Source

pub fn decoration(self, decoration: impl Into<DecorationRef>) -> Tooltip

Dart Tooltip(decoration:).

Source

pub fn text_style(self, text_style: TextStyle) -> Tooltip

Dart Tooltip(textStyle:).

Source

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

Dart Tooltip(textAlign:).

Source

pub fn wait_duration(self, wait_duration: Duration) -> Tooltip

Dart Tooltip(waitDuration:).

Source

pub fn show_duration(self, show_duration: Duration) -> Tooltip

Dart Tooltip(showDuration:).

Source

pub fn exit_duration(self, exit_duration: Duration) -> Tooltip

Dart Tooltip(exitDuration:).

Source

pub fn enable_tap_to_dismiss(self, enable_tap_to_dismiss: bool) -> Tooltip

Dart Tooltip(enableTapToDismiss:).

Source

pub fn trigger_mode(self, trigger_mode: TooltipTriggerMode) -> Tooltip

Dart Tooltip(triggerMode:).

Source

pub fn enable_feedback(self, enable_feedback: bool) -> Tooltip

Dart Tooltip(enableFeedback:).

Source

pub fn on_triggered(self, on_triggered: TooltipTriggeredCallback) -> Tooltip

Dart Tooltip(onTriggered:).

Source

pub fn mouse_cursor(self, mouse_cursor: MouseCursorRef) -> Tooltip

Dart Tooltip(mouseCursor:).

Source

pub fn ignore_pointer(self, ignore_pointer: bool) -> Tooltip

Dart Tooltip(ignorePointer:).

Source

pub fn position_delegate( self, position_delegate: TooltipPositionDelegate, ) -> Tooltip

Dart Tooltip(positionDelegate:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> Tooltip

Dart Tooltip(child:).

Source

pub fn dismiss_all_tool_tips(app: &mut App) -> bool

Dismiss all of the tooltips that are currently shown on the screen, including those with mouse cursors currently hovering over them.

This method returns true if it successfully dismisses at least one tooltip and returns false if there is no tooltip currently displayed.

Trait Implementations§

Source§

impl Debug for Tooltip

Source§

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

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

impl Default for Tooltip

Source§

fn default() -> Tooltip

Returns the “default value” for a type. Read more
Source§

impl StatefulWidget for Tooltip

Source§

type State = TooltipState

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 create_state(&self) -> TooltipState

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

fn debug_check_constructor(&self)

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 Tooltip

§

impl !Send for Tooltip

§

impl !Sync for Tooltip

§

impl !UnwindSafe for Tooltip

§

impl Forget for Tooltip

§

impl Freeze for Tooltip
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn InlineSpan> is !null: Freeze, PhantomData<RcInner<dyn InlineSpan>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const RcInner<dyn Decoration> is !null: Freeze, PhantomData<RcInner<dyn Decoration>>: 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, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, NonZero<u32>: Freeze, *const (): Freeze, *const RcInner<dyn MouseCursor> is !null: Freeze, PhantomData<RcInner<dyn MouseCursor>>: Freeze, *const RcInner<dyn Fn(TooltipPositionContext) -> Offset> is !null: Freeze, PhantomData<RcInner<dyn Fn(TooltipPositionContext) -> Offset>>: Freeze,

§

impl Move for Tooltip

§

impl Unpin for Tooltip

§

impl UnsafeUnpin for Tooltip

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>