showOverlay method
Loads the tooltip into view
Implementation
void showOverlay(BuildContext context) async {
if (overlayEntry != null) return;
OverlayState? overlayState = Overlay.of(context);
/// By calling [PositionManager.load()] we get returned the position
/// of the tooltip, the arrow and the trigger.
ToolTipElementsDisplay toolTipElementsDisplay = PositionManager(
showArrow: widget.model.arrow,
arrowBox: _arrowBox,
overlayBox: _overlayBox,
triggerBox: _triggerBox,
screenSize: _screenSize,
distance: widget.model.distance,
radius: widget.model.radius,
).load(preferredPosition: widget.position);
// build the overlay
List<Widget> children = [];
// modal curtain
if (widget.model.modal) {
children
.add(Modal(visible: widget.model.modal, onTap: () => hideOverlay()));
}
// bubble
var bubble = Positioned(
top: toolTipElementsDisplay.bubble.y,
left: toolTipElementsDisplay.bubble.x,
child: Bubble(
padding: widget.model.paddingTop ?? 10,
radius: toolTipElementsDisplay.radius,
color: widget.model.color ??
Theme.of(context).colorScheme.surfaceVariant,
child: widget.content,
));
children.add(bubble);
// arrow
var arrow = widget.model.arrow
? Positioned(
top: toolTipElementsDisplay.arrow.y,
left: toolTipElementsDisplay.arrow.x,
child: Arrow(
color: widget.model.color ??
Theme.of(context).colorScheme.surfaceVariant,
position: toolTipElementsDisplay.position,
width: _arrowBox.w,
height: _arrowBox.h))
: Container();
children.add(arrow);
// child
if (widget.model.modal) {
children.add(
Positioned(top: _triggerBox.y, left: _triggerBox.x, child: view));
}
// build overlay
overlayEntry =
OverlayEntry(builder: (context) => Stack(children: children));
overlayState.insert(overlayEntry!);
// Add timeout for the tooltip to disappear after a few seconds
if (widget.model.timeout > 0 && opener != OpenMethods.hover) {
await Future.delayed(Duration(
milliseconds:
widget.model.timeout > 0 ? widget.model.timeout : 3000))
.whenComplete(() => hideOverlay());
}
}