Skip to content

Commit 2e16142

Browse files
feat: ✨ Add skipIfTargetNotPresent property to showcase_view.dart (#626)
1 parent 5afab59 commit 2e16142

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
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
99
- Feature [#624](https://github.com/SimformSolutionsPvtLtd/showcaseview/pull/624): Added dynamic onStart callback registration with `addOnStartCallback` and `removeOnStartCallback` methods
10+
- Feature [#626](https://github.com/SimformSolutionsPvtLtd/showcaseview/pull/626): Added
11+
`skipIfTargetNotPresent` property to `showcase_view.dart`
1012

1113
## [5.0.1]
1214

lib/src/showcase/showcase_view.dart

Lines changed: 27 additions & 10 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,12 @@ 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+
///
119+
/// Defaults to false.
120+
final bool skipIfTargetNotPresent;
121+
115122
/// Whether all showcases will auto sequentially start
116123
/// having time interval of [autoPlayDelay].
117124
bool autoPlay;
@@ -414,7 +421,7 @@ class ShowcaseView {
414421
// Update active widget ID before starting the next showcase
415422
_activeWidgetId = id;
416423

417-
if (_activeWidgetId! >= _ids!.length) {
424+
if (_activeWidgetId! >= _ids!.length || _activeWidgetId!.isNegative) {
418425
_cleanupAfterSteps();
419426
onFinish?.call();
420427
for (final callback in _onFinishCallbacks) {
@@ -423,7 +430,7 @@ class ShowcaseView {
423430
} else {
424431
// Add a short delay before starting the next showcase to ensure proper state update
425432
// Then start the new showcase
426-
Future.microtask(_onStart);
433+
Future.microtask(() => _onStart(type));
427434
}
428435
},
429436
);
@@ -477,21 +484,28 @@ class ShowcaseView {
477484
/// Internal method to handle showcase start.
478485
///
479486
/// Initializes controllers and sets up auto-play timer if enabled.
480-
Future<void> _onStart() async {
487+
Future<void> _onStart([
488+
ShowcaseProgressType type = ShowcaseProgressType.forward,
489+
]) async {
481490
_activeWidgetId ??= 0;
482491
if (_activeWidgetId! < _ids!.length) {
483-
onStart?.call(_activeWidgetId, _ids![_activeWidgetId!]);
484-
// Call all registered onStart callbacks
485-
for (final callback in _onStartCallbacks) {
486-
callback.call(_activeWidgetId, _ids![_activeWidgetId!]);
487-
}
488-
489492
final controllers = _getCurrentActiveControllers;
490493
final controllerLength = controllers.length;
491-
final firstController = controllers.firstOrNull;
494+
if (skipIfTargetNotPresent && controllerLength == 0) {
495+
// If the controller is not present, skip this showcase and move to the
496+
// next one
497+
_changeSequence(type);
498+
return;
499+
}
492500

501+
final firstController = controllers.firstOrNull;
493502
final isAutoScroll =
494503
firstController?.config.enableAutoScroll ?? enableAutoScroll;
504+
onStart?.call(_activeWidgetId, _ids![_activeWidgetId!]);
505+
// Call all registered onStart callbacks
506+
for (final callback in _onStartCallbacks) {
507+
callback.call(_activeWidgetId, _ids![_activeWidgetId!]);
508+
}
495509

496510
// Auto scroll is not supported for multi-showcase feature.
497511
if (controllerLength == 1 && isAutoScroll) {
@@ -521,6 +535,9 @@ class ShowcaseView {
521535
Future<void> _onComplete() async {
522536
final currentControllers = _getCurrentActiveControllers;
523537
final controllerLength = currentControllers.length;
538+
if (skipIfTargetNotPresent && controllerLength == 0) {
539+
return;
540+
}
524541

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

0 commit comments

Comments
 (0)