Skip to content

Commit 168dd06

Browse files
Sahil-Simformaditya-css
authored andcommitted
feat: ✨Added targetTooltipGap for space between target and tooltip (#520)
1 parent 080344f commit 168dd06

File tree

8 files changed

+57
-21
lines changed

8 files changed

+57
-21
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020
Bumped dart minimum sdk to 2.19.6
2121
- Fixed [#515](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/515) - Added
2222
missing assertions for `Showcase.withWidget()`.
23+
- Feature [#518](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/pull/518) - created
24+
a showcaseView and overlay manager classes to handle showcaseView widget functionality
25+
independently.
26+
- Feature [#518](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/pull/518) -
27+
Deprecated `ShowCaseWidget`
28+
widget and added `ShowcaseView` class to handle showcase widget functionality independently
29+
without context.
30+
- Format [#528](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/pull/528) - Formatted
31+
project structure
32+
- Fixed [#526](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/526) - Fixed
33+
screen edge assertions.
34+
- Feature [#521](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/521) - Added
35+
`toolTipMargin` support for `Showcase.withWidget`
36+
- Feature [#520](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/520) - Added
37+
`targetTooltipGap` to manage space between tooltip and target widget
2338

2439
## [4.0.1]
2540
- Fixed [#493](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/493) - ShowCase.withWidget not showing issue

lib/src/showcase/showcase.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class Showcase extends StatefulWidget {
300300
/// for this showcase.
301301
final bool? enableAutoScroll;
302302

303+
/// Defines the space between target widget and tooltip.
304+
///
305+
/// Defaults to 10.
306+
final double targetTooltipGap;
307+
303308
/// Highlights a specific widget on the screen with an informative tooltip.
304309
///
305310
/// This widget helps you showcase specific parts of your UI by drawing an
@@ -326,6 +331,7 @@ class Showcase extends StatefulWidget {
326331
/// - `tooltipPadding`: Padding around the content inside the tooltip.
327332
/// - `onToolTipClick`: A callback function called when the user clicks the tooltip.
328333
/// - `tooltipBorderRadius`: The border radius of the tooltip (defaults to 8dp).
334+
/// - `targetTooltipGap`: The gap between the target widget and the tooltip (defaults to 10dp).
329335
///
330336
/// **Highlight:**
331337
/// - `targetShapeBorder`: The border to draw around the showcased widget (defaults to a rounded rectangle).
@@ -419,10 +425,15 @@ class Showcase extends StatefulWidget {
419425
this.scrollAlignment = 0.5,
420426
this.enableAutoScroll,
421427
this.floatingActionWidget,
428+
this.targetTooltipGap = 10,
422429
}) : height = null,
423430
width = null,
424431
container = null,
425432
showcaseKey = key,
433+
assert(
434+
targetTooltipGap >= 0,
435+
'targetTooltipGap must be greater than 0',
436+
),
426437
assert(
427438
overlayOpacity >= 0.0 && overlayOpacity <= 1.0,
428439
'overlay opacity must be between 0 and 1.',
@@ -523,6 +534,7 @@ class Showcase extends StatefulWidget {
523534
this.scrollAlignment = 0.5,
524535
this.enableAutoScroll,
525536
this.toolTipMargin = 14,
537+
this.targetTooltipGap = 10,
526538
}) : showArrow = false,
527539
onToolTipClick = null,
528540
scaleAnimationDuration = const Duration(milliseconds: 300),
@@ -546,6 +558,10 @@ class Showcase extends StatefulWidget {
546558
titleTextDirection = null,
547559
descriptionTextDirection = null,
548560
showcaseKey = key,
561+
assert(
562+
targetTooltipGap >= 0,
563+
'targetTooltipGap must be greater than 0',
564+
),
549565
assert(
550566
overlayOpacity >= 0.0 && overlayOpacity <= 1.0,
551567
'overlay opacity must be between 0 and 1.',

lib/src/showcase/showcase_controller.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ class ShowcaseController {
269269
tooltipActionConfig: _getTooltipActionConfig(),
270270
tooltipActions: _getTooltipActions(),
271271
targetPadding: config.targetPadding,
272+
targetTooltipGap: config.targetTooltipGap,
272273
showcaseController: this,
273274
),
274275
if (_getFloatingActionWidget != null) _getFloatingActionWidget!,

lib/src/tooltip/animated_tooltip_layout.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class _AnimatedTooltipMultiLayout extends MultiChildRenderObjectWidget {
4545
required this.screenEdgePadding,
4646
required this.targetPadding,
4747
required this.showcaseOffset,
48+
required this.targetTooltipGap,
4849
});
4950

5051
final AnimationController scaleController;
@@ -63,6 +64,7 @@ class _AnimatedTooltipMultiLayout extends MultiChildRenderObjectWidget {
6364
final double screenEdgePadding;
6465
final EdgeInsets targetPadding;
6566
final Offset showcaseOffset;
67+
final double targetTooltipGap;
6668

6769
@override
6870
RenderObject createRenderObject(BuildContext context) {
@@ -83,6 +85,7 @@ class _AnimatedTooltipMultiLayout extends MultiChildRenderObjectWidget {
8385
screenEdgePadding: screenEdgePadding,
8486
targetPadding: targetPadding,
8587
showcaseOffset: showcaseOffset,
88+
targetTooltipGap: targetTooltipGap,
8689
);
8790
}
8891

@@ -106,6 +109,7 @@ class _AnimatedTooltipMultiLayout extends MultiChildRenderObjectWidget {
106109
..toolTipSlideEndDistance = toolTipSlideEndDistance
107110
..gapBetweenContentAndAction = gapBetweenContentAndAction
108111
..targetPadding = targetPadding
109-
..showcaseOffset = showcaseOffset;
112+
..showcaseOffset = showcaseOffset
113+
..targetTooltipGap = targetTooltipGap;
110114
}
111115
}

lib/src/tooltip/render_animation_delegate.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class _RenderAnimationDelegate extends _RenderPositionDelegate {
5151
required super.screenEdgePadding,
5252
required super.targetPadding,
5353
required super.showcaseOffset,
54+
required super.targetTooltipGap,
5455
}) : _scaleController = scaleController,
5556
_moveController = moveController,
5657
_scaleAnimation = scaleAnimation,

lib/src/tooltip/render_position_delegate.dart

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class _RenderPositionDelegate extends RenderBox
5252
required this.screenEdgePadding,
5353
required this.targetPadding,
5454
required this.showcaseOffset,
55+
required this.targetTooltipGap,
5556
});
5657

5758
// Core positioning parameters
@@ -65,6 +66,7 @@ class _RenderPositionDelegate extends RenderBox
6566
double gapBetweenContentAndAction;
6667
double screenEdgePadding;
6768
EdgeInsets targetPadding;
69+
double targetTooltipGap;
6870

6971
/// This is used when there is some space around showcaseview as this widget
7072
/// implementation works in global coordinate system so because of that we
@@ -325,7 +327,7 @@ class _RenderPositionDelegate extends RenderBox
325327
? targetPosition.dx -
326328
showcaseOffset.dx -
327329
screenEdgePadding -
328-
Constants.tooltipOffset -
330+
targetTooltipGap -
329331
targetPadding.left -
330332
_getArrowPadding
331333
: screenSize.width - screenEdgePadding - _xOffset - targetPadding.right;
@@ -489,9 +491,7 @@ class _RenderPositionDelegate extends RenderBox
489491

490492
/// Calculate extra vertical component height for arrow and padding
491493
double _calculateExtraVerticalHeight() {
492-
return tooltipPosition.isVertical
493-
? Constants.tooltipOffset + _getArrowPadding
494-
: 0;
494+
return tooltipPosition.isVertical ? targetTooltipGap + _getArrowPadding : 0;
495495
}
496496

497497
/// Handle tooltip exceeding top or bottom screen edge
@@ -639,7 +639,7 @@ class _RenderPositionDelegate extends RenderBox
639639
tooltipPosition = TooltipPosition.top;
640640
_yOffset = targetPosition.dy -
641641
_toolTipBoxSize.height -
642-
Constants.tooltipOffset -
642+
targetTooltipGap -
643643
_getArrowPadding;
644644
break;
645645

@@ -648,7 +648,7 @@ class _RenderPositionDelegate extends RenderBox
648648
tooltipPosition = TooltipPosition.bottom;
649649
_yOffset = targetPosition.dy +
650650
targetSize.height +
651-
Constants.tooltipOffset +
651+
targetTooltipGap +
652652
_getArrowPadding;
653653
break;
654654

@@ -657,7 +657,7 @@ class _RenderPositionDelegate extends RenderBox
657657
tooltipPosition = TooltipPosition.right;
658658
_xOffset = targetPosition.dx +
659659
targetSize.width +
660-
Constants.tooltipOffset +
660+
targetTooltipGap +
661661
_getArrowPadding;
662662
break;
663663

@@ -666,7 +666,7 @@ class _RenderPositionDelegate extends RenderBox
666666
tooltipPosition = TooltipPosition.left;
667667
_xOffset = targetPosition.dx -
668668
_toolTipBoxSize.width -
669-
Constants.tooltipOffset -
669+
targetTooltipGap -
670670
_getArrowPadding;
671671
break;
672672
}
@@ -856,8 +856,7 @@ class _RenderPositionDelegate extends RenderBox
856856
// Center horizontally below target
857857
xOffset = targetPosition.dx + centerDxForTooltip;
858858
// Position below target with appropriate offset
859-
yOffset =
860-
targetPosition.dy + targetSize.height + Constants.tooltipOffset;
859+
yOffset = targetPosition.dy + targetSize.height + targetTooltipGap;
861860
// Add additional padding if arrow is shown
862861

863862
yOffset += _getArrowPadding;
@@ -870,15 +869,15 @@ class _RenderPositionDelegate extends RenderBox
870869
// Position above target with appropriate offset
871870
yOffset = targetPosition.dy -
872871
toolTipBoxSize.height -
873-
Constants.tooltipOffset -
872+
targetTooltipGap -
874873
_getArrowPadding;
875874
break;
876875

877876
case TooltipPosition.left:
878877
// Position to the left of target with appropriate offset
879878
xOffset = targetPosition.dx -
880879
toolTipBoxSize.width -
881-
Constants.tooltipOffset -
880+
targetTooltipGap -
882881
_getArrowPadding;
883882

884883
// Center vertically beside target
@@ -889,7 +888,7 @@ class _RenderPositionDelegate extends RenderBox
889888
// Position to the right of target with appropriate offset
890889
xOffset = targetPosition.dx +
891890
targetSize.width +
892-
Constants.tooltipOffset +
891+
targetTooltipGap +
893892
_getArrowPadding;
894893

895894
// Center vertically beside target
@@ -920,29 +919,29 @@ class _RenderPositionDelegate extends RenderBox
920919
final isBottom = targetPosition.dy +
921920
targetSize.height +
922921
totalHeight +
923-
Constants.tooltipOffset +
922+
targetTooltipGap +
924923
arrowPadding -
925924
showcaseOffset.dy <=
926925
screenSize.height - screenEdgePadding;
927926

928927
final isTop = targetPosition.dy -
929928
totalHeight -
930-
Constants.tooltipOffset -
929+
targetTooltipGap -
931930
arrowPadding -
932931
showcaseOffset.dy >=
933932
screenEdgePadding;
934933

935934
final isLeft = targetPosition.dx -
936935
tooltipSize.width -
937-
Constants.tooltipOffset -
936+
targetTooltipGap -
938937
arrowPadding -
939938
showcaseOffset.dx >=
940939
screenEdgePadding;
941940

942941
final isRight = targetPosition.dx +
943942
targetSize.width +
944943
tooltipSize.width +
945-
Constants.tooltipOffset +
944+
targetTooltipGap +
946945
arrowPadding -
947946
showcaseOffset.dx <=
948947
screenSize.width - screenEdgePadding;

lib/src/tooltip/tooltip_widget.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ToolTipWidget extends StatefulWidget {
5050
required this.showcaseController,
5151
required this.tooltipPadding,
5252
required this.toolTipSlideEndDistance,
53+
required this.targetTooltipGap,
5354
this.scaleAnimationAlignment,
5455
this.tooltipPosition,
5556
this.titlePadding,
@@ -90,6 +91,7 @@ class ToolTipWidget extends StatefulWidget {
9091
final List<Widget> tooltipActions;
9192
final EdgeInsets targetPadding;
9293
final ShowcaseController showcaseController;
94+
final double targetTooltipGap;
9395

9496
@override
9597
State<ToolTipWidget> createState() => _ToolTipWidgetState();
@@ -272,6 +274,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
272274
showcaseOffset: widget.showcaseController.rootRenderObject
273275
?.localToGlobal(Offset.zero) ??
274276
Offset.zero,
277+
targetTooltipGap: widget.targetTooltipGap,
275278
children: [
276279
_TooltipLayoutId(
277280
id: TooltipLayoutSlot.tooltipBox,

lib/src/utils/constants.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class Constants {
3838
/// Padding when arrow is not visible
3939
static const double withOutArrowToolTipPadding = 0;
4040

41-
/// Distance between target and tooltip
42-
static const double tooltipOffset = 10;
43-
4441
/// Minimum tooltip dimensions to maintain usability
4542
static const double minimumToolTipWidth = 50;
4643
// Currently we are not constraining height but will do in future

0 commit comments

Comments
 (0)