Skip to content

Commit 3ccfb9a

Browse files
committed
feat: ✨ Add skipIfTargetNotPresent property to showcase_view.dart
1 parent 65c1929 commit 3ccfb9a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- Feature [#600](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/600) - Added dynamic onComplete callback registration with `addOnCompleteCallback` and `removeOnCompleteCallback` methods
77
- Fixed [#577](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/577) - Resolve issue where long tooltip text was rendered outside the screen bounds
88
- Feature [#586](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/586): Enhance tooltip accessibility using Semantics live region
9+
- Feature [#626](https://github.com/SimformSolutionsPvtLtd/showcaseview/pull/626): Added
10+
`skipIfTargetNotPresent` property to `showcase_view.dart`
911

1012
## [5.0.1]
1113

lib/src/showcase/showcase_view.dart

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ShowcaseView {
6666
this.onFinish,
6767
this.onComplete,
6868
this.onDismiss,
69+
this.skipIfTargetNotPresent = false,
6970
this.enableShowcase = true,
7071
this.autoPlay = false,
7172
this.autoPlayDelay = Constants.defaultAutoPlayDelay,
@@ -112,6 +113,10 @@ class ShowcaseView {
112113
/// Triggered every time on completion of each showcase.
113114
final OnShowcaseCallback? onComplete;
114115

116+
/// Whether to skip showcasing widgets that are not currently present in the
117+
/// widget tree.
118+
final bool skipIfTargetNotPresent;
119+
115120
/// Whether all showcases will auto sequentially start
116121
/// having time interval of [autoPlayDelay].
117122
bool autoPlay;
@@ -400,7 +405,7 @@ class ShowcaseView {
400405
// Update active widget ID before starting the next showcase
401406
_activeWidgetId = id;
402407

403-
if (_activeWidgetId! >= _ids!.length) {
408+
if (_activeWidgetId! >= _ids!.length || _activeWidgetId!.isNegative) {
404409
_cleanupAfterSteps();
405410
onFinish?.call();
406411
for (final callback in _onFinishCallbacks) {
@@ -409,7 +414,7 @@ class ShowcaseView {
409414
} else {
410415
// Add a short delay before starting the next showcase to ensure proper state update
411416
// Then start the new showcase
412-
Future.microtask(_onStart);
417+
Future.microtask(() => _onStart(type));
413418
}
414419
},
415420
);
@@ -463,16 +468,24 @@ class ShowcaseView {
463468
/// Internal method to handle showcase start.
464469
///
465470
/// Initializes controllers and sets up auto-play timer if enabled.
466-
Future<void> _onStart() async {
471+
Future<void> _onStart([
472+
ShowcaseProgressType type = ShowcaseProgressType.forward,
473+
]) async {
467474
_activeWidgetId ??= 0;
468475
if (_activeWidgetId! < _ids!.length) {
469-
onStart?.call(_activeWidgetId, _ids![_activeWidgetId!]);
470476
final controllers = _getCurrentActiveControllers;
471477
final controllerLength = controllers.length;
472-
final firstController = controllers.firstOrNull;
478+
if (skipIfTargetNotPresent && controllerLength == 0) {
479+
// If the controller is not present, skip this showcase and move to the
480+
// next one
481+
_changeSequence(type);
482+
return;
483+
}
473484

485+
final firstController = controllers.firstOrNull;
474486
final isAutoScroll =
475487
firstController?.config.enableAutoScroll ?? enableAutoScroll;
488+
onStart?.call(_activeWidgetId, _ids![_activeWidgetId!]);
476489

477490
// Auto scroll is not supported for multi-showcase feature.
478491
if (controllerLength == 1 && isAutoScroll) {
@@ -503,6 +516,9 @@ class ShowcaseView {
503516
Future<void> _onComplete() async {
504517
final currentControllers = _getCurrentActiveControllers;
505518
final controllerLength = currentControllers.length;
519+
if (skipIfTargetNotPresent && controllerLength == 0) {
520+
return;
521+
}
506522

507523
await Future.wait([
508524
for (var i = 0; i < controllerLength; i++)

0 commit comments

Comments
 (0)