Skip to content

Commit ea99366

Browse files
feat: ✨Added on dismiss callback in showcase view widget (#500) (#502)
1 parent 9435913 commit ea99366

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [4.1.0] - (UnRelease)
2+
- Feature [#500](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/500) -
3+
Added `onDismiss` callback in `ShowCaseWidget` which will trigger whenever `onDismiss` method is
4+
called
5+
16
## [4.0.1]
27
- Fixed [#493](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/493) - ShowCase.withWidget not showing issue
38

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ WidgetsBinding.instance.addPostFrameCallback((_) =>
151151
| onStart | Function(int?, GlobalKey)? | | Triggered on start of each showcase. |
152152
| onComplete | Function(int?, GlobalKey)? | | Triggered on completion of each showcase. |
153153
| onFinish | VoidCallback? | | Triggered when all the showcases are completed. |
154+
| onDismiss | OnDismissCallback? | | Triggered when onDismiss is called |
154155
| enableShowcase | bool | true | Enable or disable showcase globally. |
155156
| toolTipMargin | double | 14 | For tooltip margin. |
156157
| globalTooltipActionConfig | TooltipActionConfig? | | Global tooltip actionbar config. |

example/lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class MyApp extends StatelessWidget {
8989
hideActionWidgetForShowcase: [_lastShowcaseWidget],
9090
),
9191
],
92+
onDismiss: (key) {
93+
debugPrint('Dismissed at $key');
94+
},
9295
),
9396
),
9497
);

lib/src/showcase_widget.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import 'package:flutter/material.dart';
2525
import '../showcaseview.dart';
2626

2727
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,
2934
);
3035

3136
class ShowCaseWidget extends StatefulWidget {
@@ -34,6 +39,9 @@ class ShowCaseWidget extends StatefulWidget {
3439
/// Triggered when all the showcases are completed.
3540
final VoidCallback? onFinish;
3641

42+
/// Triggered when onDismiss is called
43+
final OnDismissCallback? onDismiss;
44+
3745
/// Triggered every time on start of each showcase.
3846
final Function(int?, GlobalKey)? onStart;
3947

@@ -118,6 +126,7 @@ class ShowCaseWidget extends StatefulWidget {
118126
/// - `onFinish`: A callback function triggered when all showcases are completed.
119127
/// - `onStart`: A callback function triggered at the start of each showcase, providing the index and key of the target widget.
120128
/// - `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.
121130
/// - `autoPlay`: Whether to automatically start showcasing the next widget after a delay (defaults to `false`).
122131
/// - `autoPlayDelay`: The delay between each showcase during auto-play (defaults to 2 seconds).
123132
/// - `enableAutoPlayLock`: Whether to block user interaction while auto-play is enabled (defaults to `false`).
@@ -137,6 +146,7 @@ class ShowCaseWidget extends StatefulWidget {
137146
this.onFinish,
138147
this.onStart,
139148
this.onComplete,
149+
this.onDismiss,
140150
this.autoPlay = false,
141151
this.autoPlayDelay = const Duration(milliseconds: 2000),
142152
this.enableAutoPlayLock = false,
@@ -322,6 +332,14 @@ class ShowCaseWidgetState extends State<ShowCaseWidget> {
322332

323333
/// Dismiss entire showcase view
324334
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+
325343
if (mounted) setState(_cleanupAfterSteps);
326344
}
327345

0 commit comments

Comments
 (0)