Skip to content

Commit fab74b4

Browse files
committed
feat: ✨ Add onStart callback
1 parent 65c1929 commit fab74b4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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 [#624](https://github.com/SimformSolutionsPvtLtd/showcaseview/pull/624): Added onStart callback in ShowcaseView to trigger actions when a showcase starts
910

1011
## [5.0.1]
1112

lib/src/showcase/showcase_view.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ class ShowcaseView {
192192
/// Stores functions to call when a onComplete event occurs.
193193
final List<OnShowcaseCallback> _onCompleteCallbacks = [];
194194

195+
/// Stores functions to call when a onStart event occurs.
196+
final List<OnShowcaseCallback> _onStartCallbacks = [];
197+
195198
/// Returns whether showcase is completed or not.
196199
bool get isShowCaseCompleted => _ids == null && _activeWidgetId == null;
197200

@@ -359,6 +362,16 @@ class ShowcaseView {
359362
_onCompleteCallbacks.remove(listener);
360363
}
361364

365+
/// Adds a listener that will be called when the showcase tour is started.
366+
void addOnStartCallback(OnShowcaseCallback listener) {
367+
_onStartCallbacks.add(listener);
368+
}
369+
370+
/// Removes a listener that was previously added via [addOnStartCallback].
371+
void removeOnStartCallback(OnShowcaseCallback listener) {
372+
_onStartCallbacks.remove(listener);
373+
}
374+
362375
void _startShowcase(
363376
Duration delay,
364377
List<GlobalKey<State<StatefulWidget>>> widgetIds,
@@ -467,6 +480,11 @@ class ShowcaseView {
467480
_activeWidgetId ??= 0;
468481
if (_activeWidgetId! < _ids!.length) {
469482
onStart?.call(_activeWidgetId, _ids![_activeWidgetId!]);
483+
// Call all registered onStart callbacks
484+
for (final callback in _onStartCallbacks) {
485+
callback.call(_activeWidgetId, _ids![_activeWidgetId!]);
486+
}
487+
470488
final controllers = _getCurrentActiveControllers;
471489
final controllerLength = controllers.length;
472490
final firstController = controllers.firstOrNull;
@@ -486,7 +504,6 @@ class ShowcaseView {
486504
}
487505

488506
// Cancel any existing timer before setting up a new one
489-
490507
if (autoPlay) {
491508
_cancelTimer();
492509
final config = _getCurrentActiveControllers.firstOrNull?.config;

0 commit comments

Comments
 (0)