Skip to content

Commit

Permalink
Tooltip position calculation update based on available window. From PR
Browse files Browse the repository at this point in the history
  • Loading branch information
faiyaz-shaikh committed Jan 30, 2023
1 parent 2402f14 commit bba5f29
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
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

0 comments on commit bba5f29

Please sign in to comment.