Hint class Hints
A tooltip, a persistent hint or a programmatic callout attached to child.
One widget covers all three, because they differ only in what opens them:
// A tooltip.
Hint(
message: 'Delete this shift',
triggers: const <HintTrigger>{HintTrigger.longPress, HintTrigger.hover},
child: IconButton(icon: const Icon(Icons.delete), onPressed: _delete),
)
// A hint on a disabled control — the case other packages cannot do.
Hint(
message: 'You need an active shift to check in',
child: ElevatedButton(onPressed: null, child: const Text('Check in')),
)
// A programmatic hint.
Hint(
controller: _controller,
triggers: const <HintTrigger>{HintTrigger.manual},
message: 'Saved',
child: saveButton,
)
Why it works on disabled widgets
Triggers are recognised from a Listener, which reads raw pointer events and never enters the gesture arena. That has two consequences, both of them the point of this package:
- a child that ignores pointers —
ElevatedButton(onPressed: null)— does not stop the hint from seeing the touch, and - a child that does handle pointers keeps its gesture: the hint never competes for it, so wrapping an enabled button changes nothing about how that button behaves.
The one case this cannot win is an IgnorePointer or AbsorbPointer
above the hint in the tree: it stops the pointer before it ever reaches
the hint. Put the Hint outside the IgnorePointer instead:
// Does not work: the hint never sees the pointer.
IgnorePointer(child: Hint(message: '...', child: button))
// Works.
Hint(message: '...', child: IgnorePointer(child: button))
Overlay lifetime
The bubble is shown with an OverlayPortal, so its lifetime is tied to this widget's element. Popping the route mid-tooltip takes the bubble with it; there is no OverlayEntry left behind to leak.
- Inheritance
Constructors
-
Hint({required Widget child, String? message, String? title, HintContentBuilder? contentBuilder, HintController? controller, Set<
HintTrigger> triggers = const <HintTrigger>{HintTrigger.longPress, HintTrigger.hover}, HintDirection direction = HintDirection.auto, HintThemeData? theme, bool absorbChildInput = false, bool interactive = false, bool exclusive = true, bool dismissOnTapOutside = true, Duration waitDuration = Duration.zero, Duration? showDuration, Color? barrierColor, bool followTarget = false, String? semanticsLabel, bool excludeFromSemantics = false, String? showOnce, String? analyticsId, MouseCursor? mouseCursor, bool followPointer = false, VoidCallback? onShow, VoidCallback? onDismiss, Key? key}) -
Creates a hint attached to
child.const
Properties
- absorbChildInput → bool
-
Inserts a transparent hit layer above child.
final
- analyticsId → String?
-
A stable identifier reported to a HintObserver.
final
- barrierColor → Color?
-
Paints a full-screen scrim behind the bubble.
final
- child → Widget
-
The widget the hint is attached to and points at.
final
- contentBuilder → HintContentBuilder?
-
Builds arbitrary bubble content.
final
- controller → HintController?
-
Drives the hint programmatically. See HintController.
final
- direction → HintDirection
-
Which side of the target the bubble prefers. See HintDirection.
final
- dismissOnTapOutside → bool
-
Whether a pointer down outside the bubble dismisses it.
final
- excludeFromSemantics → bool
-
Whether to skip adding a semantic tooltip to the target.
final
- exclusive → bool
-
Whether opening this hint closes any other open hint.
final
- followPointer → bool
-
Anchors the bubble to the pointer instead of to the target.
final
- followTarget → bool
-
Re-measures the target every frame instead of on scroll and resize.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- interactive → bool
-
Whether the pointer may move from the target into the bubble without
dismissing it.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- message → String?
-
The bubble's body text.
final
- mouseCursor → MouseCursor?
-
The cursor shown while the pointer is over the target.
final
- onDismiss → VoidCallback?
-
Called when the hint closes, for any reason.
final
- onShow → VoidCallback?
-
Called when the hint opens. Useful for onboarding funnels.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticsLabel → String?
-
Overrides the text a screen reader gets, in both places the hint speaks:
the target's semantic tooltip, and the open bubble.
final
- showDuration → Duration?
-
Auto-hide delay. Null keeps the hint open until something closes it.
final
- showOnce → String?
-
Shows this hint only the first time, ever, under this key.
final
- theme → HintThemeData?
-
Per-instance visual overrides, merged over the ambient theme field by
field.
final
- title → String?
-
An optional bold line above message.
final
-
triggers
→ Set<
HintTrigger> -
What opens the hint. See HintTrigger.
final
- waitDuration → Duration
-
How long the pointer must rest on the target before a hover shows the
hint.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Hint> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited