Skip to content

Conversation

@memishood
Copy link
Contributor

@memishood memishood commented Aug 11, 2025

Description

Currently, the onFinish and onDismiss callbacks can only be defined when ShowcaseView is registered, which is often at a global level. This forces developers to handle showcase completion logic far from the widget that initiated it, leading to tightly coupled code and state management challenges.

This change introduces a listener pattern, allowing any widget to subscribe to showcase events dynamically.

  • Added addOnFinishCallback and removeOnFinishCallback to allow for dynamic subscription to the showcase completion event.
  • Added addOnDismissCallback and removeOnDismissCallback for the showcase dismissal event.
  • Updated the core logic to iterate and invoke all registered listeners when a showcase is finished or dismissed, ensuring backward compatibility with the original global callbacks.
  • Ensured that all listener lists are cleared when ShowcaseView is unregistered to prevent memory leaks.

Usage Example

class MyFeatureScreen extends StatefulWidget {
  // ...
}

class _MyFeatureScreenState extends State<MyFeatureScreen> {
  void _onShowcaseFinished() {
    // Handle logic after the showcase
  }

  void _onShowcaseDismissed(GlobalKey? dismissedAt) {
    // Handle logic when showcase is dismissed
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      ShowcaseView.get().addOnFinishCallback(_onShowcaseFinished);
      ShowcaseView.get().addOnDismissCallback(_onShowcaseDismissed);
    });
  }

  @override
  void dispose() {
    ShowcaseView.get().removeOnFinishCallback(_onShowcaseFinished);
    ShowcaseView.get().removeOnDismissCallback(_onShowcaseDismissed);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ...
  }
}

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #555

@aditya-css
Copy link
Collaborator

Great work! @memishood. Thanks for raising this PR.

@aditya-css aditya-css merged commit 2cf17b3 into SimformSolutionsPvtLtd:master Aug 11, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose onFinish Callback via ShowCaseWidget.of

2 participants