@@ -25,7 +25,12 @@ import 'package:flutter/material.dart';
25
25
import '../showcaseview.dart' ;
26
26
27
27
typedef FloatingActionBuilderCallback = FloatingActionWidget Function (
28
- BuildContext ,
28
+ BuildContext context,
29
+ );
30
+
31
+ typedef OnDismissCallback = void Function (
32
+ /// this is the key on which showcase is dismissed
33
+ GlobalKey ? dismissedAt,
29
34
);
30
35
31
36
class ShowCaseWidget extends StatefulWidget {
@@ -34,6 +39,9 @@ class ShowCaseWidget extends StatefulWidget {
34
39
/// Triggered when all the showcases are completed.
35
40
final VoidCallback ? onFinish;
36
41
42
+ /// Triggered when onDismiss is called
43
+ final OnDismissCallback ? onDismiss;
44
+
37
45
/// Triggered every time on start of each showcase.
38
46
final Function (int ? , GlobalKey )? onStart;
39
47
@@ -118,6 +126,7 @@ class ShowCaseWidget extends StatefulWidget {
118
126
/// - `onFinish` : A callback function triggered when all showcases are completed.
119
127
/// - `onStart` : A callback function triggered at the start of each showcase, providing the index and key of the target widget.
120
128
/// - `onComplete` : A callback function triggered at the completion of each showcase, providing the index and key of the target widget.
129
+ /// - `onDismiss` : A callback function triggered when showcase view is dismissed.
121
130
/// - `autoPlay` : Whether to automatically start showcasing the next widget after a delay (defaults to `false` ).
122
131
/// - `autoPlayDelay` : The delay between each showcase during auto-play (defaults to 2 seconds).
123
132
/// - `enableAutoPlayLock` : Whether to block user interaction while auto-play is enabled (defaults to `false` ).
@@ -137,6 +146,7 @@ class ShowCaseWidget extends StatefulWidget {
137
146
this .onFinish,
138
147
this .onStart,
139
148
this .onComplete,
149
+ this .onDismiss,
140
150
this .autoPlay = false ,
141
151
this .autoPlayDelay = const Duration (milliseconds: 2000 ),
142
152
this .enableAutoPlayLock = false ,
@@ -322,6 +332,14 @@ class ShowCaseWidgetState extends State<ShowCaseWidget> {
322
332
323
333
/// Dismiss entire showcase view
324
334
void dismiss () {
335
+ // This will check if valid active widget id exist or not and based on that
336
+ // we will return the widget key with `onDismiss` callback or will return
337
+ // null value.
338
+ final idNotExist =
339
+ activeWidgetId == null || ids == null || ids! .length < activeWidgetId! ;
340
+
341
+ widget.onDismiss? .call (idNotExist ? null : ids? [activeWidgetId! ]);
342
+
325
343
if (mounted) setState (_cleanupAfterSteps);
326
344
}
327
345
0 commit comments