AnchoredPopup class
Positions a popup in the Overlay, anchored to a trigger's CompositedTransformTarget via link, keeping it inside the visible area.
This is the shared positioning engine for jade_ui's anchored overlays (Select/Autocomplete/Dropdown/Popover menus and Tooltip):
- All eight PlacementTokens with floating-ui semantics (
bottomcenters under the trigger,bottomLeft/bottomRightalign to its corners,left/rightsit on the sides). - Flips to the opposite side when the preferred side does not have
enough room (e.g. a
bottommenu whose trigger sits at the bottom edge of the screen renders above it). The flip is axis-aware: top↔bottom, left↔right. - Clamps into the visible area (the screen minus the keyboard) with margin when neither side fits, on both axes.
- Avoids the mobile keyboard: the visible area is derived from
MediaQuery.viewInsetsOf, so the popup repositions when the keyboard opens or closes (e.g. an autocomplete search field focused while its popup is open). - Re-measures and re-clamps when the child changes size while open (e.g. autocomplete filtering), since the offset is recomputed on every build from the last measured child size.
The popup tracks the trigger on scroll through the layer link; the flip decision itself is made from the trigger geometry captured at open time (triggerGlobalTopLeft, triggerSize).
When animation is provided, the child is wrapped in the spec's popup
entrance motion (150ms fade-in-0 zoom-in-90, --ease-out-fluid) and the
animation is started after the popup has been measured and placed at
its final offset — the first visible frame is already at the collision-free
position, so a flip never causes a visible jump. The caller owns the
controller (lifecycle and the close animation: reverse then remove the
overlay entry). scaleAlignment picks the zoom origin (tooltips scale from
their anchor edge).
Callers that render a placement-dependent arrow or slide animation (the tooltip) can track the effective geometry through onPlacementResolved, which fires once the popup has been measured and the flip decision made.
final controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 150));
Overlay.of(context).insert(OverlayEntry(
builder: (_) => AnchoredPopup(
link: layerLink,
triggerSize: triggerSize,
triggerGlobalTopLeft: triggerOffset,
animation: controller,
child: menu,
),
));
controller.forward();
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- AnchoredPopup
Constructors
-
AnchoredPopup({Key? key, required LayerLink link, required Widget child, required Size triggerSize, required Offset triggerGlobalTopLeft, double gap = 8.0, EdgeInsets margin = const EdgeInsets.all(8.0), PlacementToken placement = PlacementToken.bottom, bool matchTriggerWidth = false, AnimationController? animation, Alignment scaleAlignment = Alignment.center, ValueChanged<
AnchoredPlacement> ? onPlacementResolved, bool showWhenUnlinked = false}) -
Creates a popup that is positioned against the trigger identified by
link.const
Properties
- animation → AnimationController?
-
Entrance animation, started (from 0) once the popup is measured and
placed at its final offset. The caller owns the controller lifecycle
and the exit animation.
final
- child → Widget
-
The popup content.
final
- gap → double
-
Gap between the trigger and the popup, measured from the aligned edges
(e.g. trigger bottom edge to popup top edge for
bottomplacements).final - hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- link → LayerLink
-
The LayerLink shared with the trigger's CompositedTransformTarget.
final
- margin → EdgeInsets
-
Minimum distance kept between the popup and the visible-area edges.
final
- matchTriggerWidth → bool
-
Pin the popup width to triggerSize (list-style popups like
Select/Autocomplete). When false the popup is content-sized and
clamped horizontally into the visible area.
final
-
onPlacementResolved
→ ValueChanged<
AnchoredPlacement> ? -
Called with the effective geometry once the popup is measured and the
flip decision has been made, and again whenever it changes (e.g. after
a content-size change while open). Safe to call
markNeedsBuildfrom.final - placement → PlacementToken
-
Preferred placement. AnchoredPopup flips to the opposite side when the
preferred side doesn't fit, and clamps on both axes as a last resort.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scaleAlignment → Alignment
-
The zoom origin of the entrance animation (defaults to the popup
center; tooltips scale from their anchor edge).
final
- showWhenUnlinked → bool
-
Whether to render the child while the CompositedTransformTarget for
link is not in the tree.
final
- triggerGlobalTopLeft → Offset
-
The trigger's top-left corner in global (overlay) coordinates.
final
- triggerSize → Size
-
The trigger's size at open time (also used to pin the popup width when
matchTriggerWidth is set).
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< AnchoredPopup> -
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