Skip to content

Commit

Permalink
feat: ✨Add tooltipOffset property
Browse files Browse the repository at this point in the history
  • Loading branch information
guenth39 committed Apr 25, 2024
1 parent 2f60d93 commit 318178d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class MailTile extends StatelessWidget {
targetBorderRadius: const BorderRadius.all(
Radius.circular(150),
),
tooltipOffset: const Offset(20, -5),
container: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expand Down
8 changes: 8 additions & 0 deletions lib/src/showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ class Showcase extends StatefulWidget {
/// Defaults to 7.
final double toolTipSlideEndDistance;

/// Defines the tooltip offset from the target widget.
///
/// Default to Offset.zero
final Offset tooltipOffset;

const Showcase({
required this.key,
required this.description,
Expand Down Expand Up @@ -299,6 +304,7 @@ class Showcase extends StatefulWidget {
this.onBarrierClick,
this.disableBarrierInteraction = false,
this.toolTipSlideEndDistance = 7,
this.tooltipOffset = Offset.zero,
}) : height = null,
width = null,
container = null,
Expand Down Expand Up @@ -340,6 +346,7 @@ class Showcase extends StatefulWidget {
this.onBarrierClick,
this.disableBarrierInteraction = false,
this.toolTipSlideEndDistance = 7,
this.tooltipOffset = Offset.zero,
}) : showArrow = false,
onToolTipClick = null,
scaleAnimationDuration = const Duration(milliseconds: 300),
Expand Down Expand Up @@ -630,6 +637,7 @@ class _ShowcaseState extends State<Showcase> {
titleTextDirection: widget.titleTextDirection,
descriptionTextDirection: widget.descriptionTextDirection,
toolTipSlideEndDistance: widget.toolTipSlideEndDistance,
tooltipOffset: widget.tooltipOffset,
),
],
],
Expand Down
20 changes: 13 additions & 7 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ToolTipWidget extends StatefulWidget {
final TextDirection? titleTextDirection;
final TextDirection? descriptionTextDirection;
final double toolTipSlideEndDistance;
final Offset tooltipOffset;

const ToolTipWidget({
Key? key,
Expand All @@ -91,6 +92,7 @@ class ToolTipWidget extends StatefulWidget {
required this.tooltipBorderRadius,
required this.scaleAnimationDuration,
required this.scaleAnimationCurve,
required this.tooltipOffset,
this.scaleAnimationAlignment,
this.isTooltipDismissed = false,
this.tooltipPosition,
Expand Down Expand Up @@ -186,9 +188,9 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
if ((leftPositionValue + width) > widget.screenSize.width) {
return null;
} else if ((leftPositionValue) < _kDefaultPaddingFromParent) {
return _kDefaultPaddingFromParent;
return _kDefaultPaddingFromParent + widget.tooltipOffset.dx;
} else {
return leftPositionValue;
return leftPositionValue + widget.tooltipOffset.dx;
}
}
return null;
Expand All @@ -204,7 +206,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
final rightPosition = widget.position!.getCenter() + (width * 0.5);

return (rightPosition + width) > widget.screenSize.width
? _kDefaultPaddingFromParent
? _kDefaultPaddingFromParent + widget.tooltipOffset.dx
: null;
} else {
return null;
Expand All @@ -220,7 +222,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
} else if (space < (widget.contentWidth! / 2)) {
space = 16;
}
return space;
return space + widget.tooltipOffset.dx;
}

double _getAlignmentX() {
Expand Down Expand Up @@ -344,10 +346,12 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
contentOrientation == TooltipPosition.bottom ? 1.0 : -1.0;
isArrowUp = contentOffsetMultiplier == 1.0;

final contentY = isArrowUp
var contentY = isArrowUp
? widget.position!.getBottom() + (contentOffsetMultiplier * 3)
: widget.position!.getTop() + (contentOffsetMultiplier * 3);

contentY = contentY + widget.tooltipOffset.dy;

final num contentFractionalOffset =
contentOffsetMultiplier.clamp(-1.0, 0.0);

Expand Down Expand Up @@ -556,14 +560,16 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
double? _getArrowLeft(double arrowWidth) {
final left = _getLeft();
if (left == null) return null;
return (widget.position!.getCenter() - (arrowWidth / 2) - left);
return (widget.position!.getCenter() - (arrowWidth / 2) - left) +
widget.tooltipOffset.dx;
}

double? _getArrowRight(double arrowWidth) {
if (_getLeft() != null) return null;
return (widget.screenSize.width - widget.position!.getCenter()) -
(_getRight() ?? 0) -
(arrowWidth / 2);
(arrowWidth / 2) +
widget.tooltipOffset.dx;
}
}

Expand Down

0 comments on commit 318178d

Please sign in to comment.