Skip to content

Commit

Permalink
fix: 🐛 Take in account view insets (such as keyboard) (#288)
Browse files Browse the repository at this point in the history
* Take in account view insets (such as keyboard)

Take in account the view insets of the device, such as the keyboard that is up, so that we can correctly determine if the widget should be on top or below. If you're trying to highlight something that is at the bottom of the screen and the keyboard is up, it will try to render it below the widget, which would be under the keyboard.

By taking in account view insets we can assure that widgets that are sticky to the bottom get correctly highlighted when the keyboard is up.

To test this all you need to do is make a widget sticky to the bottom of your screen, summon the keyboard and then showcase the sticky widget. You'll see that everything is blacked out except the sticky widget, but the arrow and text message will be invisible as it's below the keyboard.

* Removed warning and analyzer error

---------

Co-authored-by: faiyaz-shaikh <[email protected]>
Co-authored-by: faiyaz <[email protected]>
  • Loading branch information
3 people authored Feb 22, 2023
1 parent 2402f14 commit ce660b5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## [2.0.1] (Unreleased)
- Add support for enabling/disabling showcase globally.
- Added support of manual vertical tooltip position.
- Fixed [#318](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/318) - Add support for enable/disable showcase globally.
- Feature [#306](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/pull/306) - Added support of manual vertical tooltip position.
- Added PR title validation workflow
- Fixed [#316](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/316) - Add title and description padding
- Fixed [#330](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/330) - Overlay not showing in flutter 3.7.0
- Fixed [#288](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/pull/288) - Take in account view insets (such as keyboard)
- Fixed [#334](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/334) - Move code line to resolve no context issue

## [2.0.0+1]
- Fixed [#237](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/261) - Feature added to enable/disable default gesture of ShowcaseView child using `disableDefaultTargetGestures` parameter
Expand Down
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
12 changes: 5 additions & 7 deletions lib/src/layout_overlays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,12 @@ 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);
}
final showCaseContext = ShowCaseWidget.of(context).context;
if (Overlay.maybeOf(showCaseContext) != null) {
Overlay.of(showCaseContext).insert(overlayEntry);
} else if (Overlay.maybeOf(context) != null) {
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 ce660b5

Please sign in to comment.