Skip to content

Commit 68aa071

Browse files
fix: 🐛 Fixed screen edge assertions (#526) (#527)
1 parent d3dfda8 commit 68aa071

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

lib/src/showcase/showcase_service.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ class ShowcaseService {
100100
final scopeName = scope ?? currentScope;
101101
final manager = _showcaseViews[scopeName];
102102
if (manager == null) {
103-
throw Exception('No ShowcaseView registered for scope "$scopeName". '
104-
'Make sure ShowcaseView is initialized in this scope.');
103+
if (scopeName != Constants.initialScope) {
104+
throw Exception('No ShowcaseView registered for scope "$scopeName". '
105+
'Make sure ShowcaseView is initialized in this scope.');
106+
} else {
107+
throw Exception('No ShowcaseView is registered. '
108+
'Make sure ShowcaseView is registered before using Showcase widget');
109+
}
105110
}
106111
return manager;
107112
}

lib/src/tooltip/render_position_delegate.dart

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,14 @@ class _RenderPositionDelegate extends RenderBox
9292
// Layout properties - keep only those not managed by RenderObjectManager
9393
var _needToResize = false;
9494
var _needToFlip = false;
95+
96+
// These are the max size tooltip can have
97+
// these can change as per the tooltip widget configuration and content
9598
var _maxWidth = 0.0;
9699
var _maxHeight = 0.0;
100+
101+
// These are the total size that we can use for tooltip
102+
// This will be fixed after initial layout and will not change after that
97103
var _availableScreenWidth = 0.0;
98104
var _availableScreenHeight = 0.0;
99105
var _minimumActionBoxSize = Size.zero;
@@ -530,7 +536,6 @@ class _RenderPositionDelegate extends RenderBox
530536
} else if (tooltipPosition.isHorizontal) {
531537
// For left/right positions, ensure height fits
532538
if (_maxHeight > _availableScreenHeight) {
533-
_maxHeight = _availableScreenHeight;
534539
_needToResize = true;
535540
_yOffset = screenEdgePadding + showcaseOffset.dy;
536541
} else if (!isTopEdge) {
@@ -574,8 +579,7 @@ class _RenderPositionDelegate extends RenderBox
574579
_maxHeight -= screenEdgePadding - _xOffset;
575580
_yOffset = screenEdgePadding + showcaseOffset.dy;
576581
} else {
577-
// Bottom edge - resize and keep at bottom
578-
_maxHeight += _calculateExtraVerticalHeight();
582+
// Bottom edge - keep at bottom
579583
_yOffset = screenSize.height -
580584
showcaseOffset.dy -
581585
screenEdgePadding -
@@ -670,7 +674,6 @@ class _RenderPositionDelegate extends RenderBox
670674

671675
/// Apply final boundary constraints to ensure tooltip stays on screen
672676
void _applyBoundaryConstraints(double tooltipHeight) {
673-
// Ensure tooltip stays within horizontal screen bounds
674677
final screenStart = Offset(
675678
screenEdgePadding + showcaseOffset.dx,
676679
screenEdgePadding + showcaseOffset.dy,
@@ -683,24 +686,22 @@ class _RenderPositionDelegate extends RenderBox
683686
showcaseOffset.dx,
684687
screenSize.height - tooltipHeight - screenEdgePadding + showcaseOffset.dy,
685688
);
686-
assert(
687-
screenStart.dx <= screenEnd.dx,
688-
'Tooltip width is more then available size',
689-
);
690-
_xOffset = _xOffset.clamp(
691-
screenStart.dx,
692-
screenEnd.dx,
693-
);
689+
690+
// Ensure tooltip stays within horizontal screen bounds
691+
_xOffset = screenStart.dx > screenEnd.dx
692+
? screenStart.dx
693+
: _xOffset.clamp(
694+
screenStart.dx,
695+
screenEnd.dx,
696+
);
694697

695698
// Ensure tooltip stays within vertical screen bounds
696-
assert(
697-
screenStart.dy <= screenEnd.dy,
698-
'Tooltip height is more then available size',
699-
);
700-
_yOffset = _yOffset.clamp(
701-
screenStart.dy,
702-
screenEnd.dy,
703-
);
699+
_yOffset = screenStart.dy > screenEnd.dy
700+
? screenStart.dy
701+
: _yOffset.clamp(
702+
screenStart.dy,
703+
screenEnd.dy,
704+
);
704705

705706
// Apply target padding based on position
706707
_applyTargetPadding();

0 commit comments

Comments
 (0)