Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Tooltip position calculation update based on the available window #328

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ analyzer:
argument_type_not_assignable: error
invalid_assignment: error
dead_code: warning
overridden_fields: ignore
use_key_in_widget_constructors: ignore

linter:
rules:
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class _MailPageState extends State<MailPage> {
disableDefaultTargetGestures: true,
child: GestureDetector(
onTap: () =>
print('menu button clicked'),
debugPrint('menu button clicked'),
child: Icon(
Icons.menu,
color: Theme.of(context).primaryColor,
Expand Down
10 changes: 4 additions & 6 deletions lib/src/layout_overlays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,10 @@ class _OverlayBuilderState extends State<OverlayBuilder> {
void addToOverlay(OverlayEntry overlayEntry) async {
final showCaseContext = ShowCaseWidget.of(context).context;
if (mounted) {
if (Overlay.of(showCaseContext) != null) {
Overlay.of(showCaseContext)!.insert(overlayEntry);
} else {
if (Overlay.of(context) != null) {
Overlay.of(context)!.insert(overlayEntry);
}
try {
Overlay.of(showCaseContext).insert(overlayEntry);
} catch (e) {
Overlay.of(context).insert(overlayEntry);
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions lib/src/tooltip_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
position.dy + ((widget.position?.getHeight() ?? 0) / 2);
final topPosition = position.dy - ((widget.position?.getHeight() ?? 0) / 2);
final hasSpaceInTop = topPosition >= height;
final EdgeInsets viewInsets = EdgeInsets.fromWindowPadding(
WidgetsBinding.instance.window.viewInsets,
WidgetsBinding.instance.window.devicePixelRatio);
final double actualVisibleScreenHeight =
(widget.screenSize?.height ?? MediaQuery.of(context).size.height) -
viewInsets.bottom;
final hasSpaceInBottom =
((widget.screenSize?.height ?? MediaQuery.of(context).size.height) -
bottomPosition) >=
height;
(actualVisibleScreenHeight - bottomPosition) >= height;
return widget.tooltipPosition ??
(hasSpaceInTop && !hasSpaceInBottom
? TooltipPosition.top
Expand All @@ -132,12 +136,12 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
final titleStyle = widget.titleTextStyle ??
Theme.of(context)
.textTheme
.headline6!
.titleLarge!
.merge(TextStyle(color: widget.textColor));
final descriptionStyle = widget.descTextStyle ??
Theme.of(context)
.textTheme
.subtitle2!
.titleSmall!
.merge(TextStyle(color: widget.textColor));
final titleLength = widget.title == null
? 0
Expand Down Expand Up @@ -424,7 +428,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
style: widget.titleTextStyle ??
Theme.of(context)
.textTheme
.headline6!
.titleLarge!
.merge(
TextStyle(
color: widget.textColor,
Expand All @@ -441,7 +445,7 @@ class _ToolTipWidgetState extends State<ToolTipWidget>
style: widget.descTextStyle ??
Theme.of(context)
.textTheme
.subtitle2!
.titleSmall!
.merge(
TextStyle(
color: widget.textColor,
Expand Down