positionDelegate property
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.
This allows for custom positioning such as left/right positioning, or any other arbitrary positioning logic.
For example, if the Overlay takes up the entire screen, returning Offset.zero will position the tooltip at the top-left corner of the screen.
The TooltipPositionContext provides information that can be used to position the tooltip relative to the target/child.
For example:
positionDelegate: (TooltipPositionContext context) {
// Use the context information to position the tooltip to the right of
// the target.
return Offset(
context.target.dx + context.targetSize.width / 2,
context.target.dy - context.tooltipSize.height / 2,
);
}
If null, defaults to positioning the tooltip center-aligned and below the target using positionDependentBox.
See also:
- TooltipPositionContext, which contains the positioning parameters.
- TooltipPositionDelegate, the function signature for custom positioning.
Implementation
final TooltipPositionDelegate? positionDelegate;