@@ -173,6 +173,12 @@ class ShowcaseView {
173
173
/// Map to store keys for which floating action widget should be hidden.
174
174
late final Map <GlobalKey , bool > _hideFloatingWidgetKeys;
175
175
176
+ /// Stores functions to call when a onFinish event occurs.
177
+ final List <VoidCallback > _onFinishCallbacks = [];
178
+
179
+ /// Stores functions to call when a onDismiss event occurs.
180
+ final List <OnDismissCallback > _onDismissCallbacks = [];
181
+
176
182
/// Returns whether showcase is completed or not.
177
183
bool get isShowCaseCompleted => _ids == null && _activeWidgetId == null ;
178
184
@@ -258,8 +264,13 @@ class ShowcaseView {
258
264
void dismiss () {
259
265
final idDoesNotExist =
260
266
_activeWidgetId == null || (_ids? .length ?? - 1 ) <= _activeWidgetId! ;
267
+ final dismissedAtKey = idDoesNotExist ? null : _ids? [_activeWidgetId! ];
268
+
269
+ onDismiss? .call (dismissedAtKey);
270
+ for (final callback in _onDismissCallbacks) {
271
+ callback.call (dismissedAtKey);
272
+ }
261
273
262
- onDismiss? .call (idDoesNotExist ? null : _ids? [_activeWidgetId! ]);
263
274
if (! _mounted) return ;
264
275
265
276
_cleanupAfterSteps ();
@@ -273,6 +284,9 @@ class ShowcaseView {
273
284
ShowcaseService .instance.unregister (scope: scope);
274
285
_mounted = false ;
275
286
_cancelTimer ();
287
+
288
+ _onFinishCallbacks.clear ();
289
+ _onDismissCallbacks.clear ();
276
290
}
277
291
278
292
/// Updates the overlay to reflect current showcase state.
@@ -301,6 +315,26 @@ class ShowcaseView {
301
315
: globalFloatingActionWidget;
302
316
}
303
317
318
+ /// Adds a listener that will be called when the showcase tour is finished.
319
+ void addOnFinishCallback (VoidCallback listener) {
320
+ _onFinishCallbacks.add (listener);
321
+ }
322
+
323
+ /// Removes a listener that was previously added via [addOnFinishCallback] .
324
+ void removeOnFinishCallback (VoidCallback listener) {
325
+ _onFinishCallbacks.remove (listener);
326
+ }
327
+
328
+ /// Adds a listener that will be called when the showcase tour is dismissed.
329
+ void addOnDismissCallback (OnDismissCallback listener) {
330
+ _onDismissCallbacks.add (listener);
331
+ }
332
+
333
+ /// Removes a listener that was previously added via [addOnDismissCallback] .
334
+ void removeOnDismissCallback (OnDismissCallback listener) {
335
+ _onDismissCallbacks.remove (listener);
336
+ }
337
+
304
338
void _startShowcase (
305
339
Duration delay,
306
340
List <GlobalKey <State <StatefulWidget >>> widgetIds,
@@ -345,6 +379,9 @@ class ShowcaseView {
345
379
if (_activeWidgetId! >= _ids! .length) {
346
380
_cleanupAfterSteps ();
347
381
onFinish? .call ();
382
+ for (final callback in _onFinishCallbacks) {
383
+ callback.call ();
384
+ }
348
385
} else {
349
386
// Add a short delay before starting the next showcase to ensure proper state update
350
387
// Then start the new showcase
0 commit comments