Skip to content

Commit a233cec

Browse files
committed
fix: 🐛 Fixed incorrect ShowcaseView callback scope by adding optional scope parameter
1 parent 6a1e76a commit a233cec

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Fixed [#590](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/590) - Fixed Rendering issues with scrollable showcase views inside withWidget
44
- Fixed [#587](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/587) - Fixed ShowcaseView.withWidget container positioning issues on web
5+
- Fixed [#588](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/588) & [#593](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/593) - Fixed incorrect ShowcaseView callback scope by adding optional scope parameter
56

67
## [5.0.1]
78

doc/documentation.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,27 @@ performed using that scope name, i.e.
606606
> If multiple scopes are registered with same name then the last registering scope would be
607607
> consider valid and the rest would be overrode by the last one.
608608
609+
## Explicit Scope Assignment with `scope`
610+
611+
By default, `Showcase` widgets use the currently active scope. However, you can explicitly
612+
assign a `Showcase` widget to a specific scope using the `scope` parameter. This is
613+
particularly useful when you need to ensure a widget belongs to a specific scope regardless
614+
of which scope is currently active.
615+
616+
```dart
617+
Showcase(
618+
key: _profileKey,
619+
scope: 'profile',
620+
title: 'Profile',
621+
description: 'Your profile information',
622+
child: Icon(Icons.person),
623+
),
624+
```
625+
626+
This approach is helpful in scenarios with multiple active scopes in the same widget tree,
627+
ensuring each `Showcase` widget targets the correct scope without relying on global state
628+
changes.
629+
609630
# Migration Guides
610631

611632
This document provides guidance for migrating between different versions of the ShowCaseView package.

example/lib/detailscreen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class _DetailState extends State<Detail> {
6767
key: _one,
6868
title: 'Title',
6969
description: 'Desc',
70+
scope: '_detailsScreen',
7071
floatingActionWidget: FloatingActionWidget(
7172
left: 16,
7273
bottom: 16,

lib/src/showcase/showcase.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class Showcase extends StatefulWidget {
112112
this.enableAutoScroll,
113113
this.floatingActionWidget,
114114
this.targetTooltipGap = 10,
115+
this.scope,
115116
}) : container = null,
116117
showcaseKey = key,
117118
assert(
@@ -201,6 +202,7 @@ class Showcase extends StatefulWidget {
201202
this.enableAutoScroll,
202203
this.toolTipMargin = 14,
203204
this.targetTooltipGap = 10,
205+
this.scope,
204206
}) : showArrow = false,
205207
onToolTipClick = null,
206208
scaleAnimationDuration = const Duration(milliseconds: 300),
@@ -258,6 +260,11 @@ class Showcase extends StatefulWidget {
258260
/// target widget while showcasing.
259261
final GlobalKey showcaseKey;
260262

263+
/// Optional scope name for this showcase widget.
264+
/// If provided, this widget will be registered under the specified scope
265+
/// instead of the current active scope.
266+
final String? scope;
267+
261268
/// Target widget that will be showcased or highlighted
262269
final Widget child;
263270

@@ -527,6 +534,10 @@ class Showcase extends StatefulWidget {
527534
}
528535

529536
class _ShowcaseState extends State<Showcase> {
537+
/// Returns the scope name for this Showcase instance.
538+
late final String _scopeName =
539+
widget.scope ?? ShowcaseService.instance.getScope().name;
540+
530541
ShowcaseController get _controller => ShowcaseService.instance.getController(
531542
key: widget.showcaseKey,
532543
id: _uniqueId,
@@ -540,7 +551,8 @@ class _ShowcaseState extends State<Showcase> {
540551
@override
541552
void initState() {
542553
super.initState();
543-
_showCaseWidgetManager = ShowcaseService.instance.getScope();
554+
_showCaseWidgetManager =
555+
ShowcaseService.instance.getScope(scope: _scopeName);
544556
ShowcaseController.register(
545557
id: _uniqueId,
546558
key: widget.showcaseKey,
@@ -603,17 +615,15 @@ class _ShowcaseState extends State<Showcase> {
603615
}
604616

605617
void _updateControllerValues() {
606-
final manager = ShowcaseService.instance.getScope(
607-
scope: _showCaseWidgetManager.name,
608-
);
618+
final manager = ShowcaseService.instance.getScope(scope: _scopeName);
609619
if (manager == _showCaseWidgetManager) return;
610620
_showCaseWidgetManager = manager;
611621
ShowcaseService.instance.addController(
612622
controller: _controller
613623
..showcaseView = _showCaseWidgetManager.showcaseView,
614624
key: widget.showcaseKey,
615625
id: _uniqueId,
616-
scope: _showCaseWidgetManager.name,
626+
scope: _scopeName,
617627
);
618628
}
619629
}

0 commit comments

Comments
 (0)