Thanks to visit codestin.com
Credit goes to github.com

Skip to content

added removeSnackBar function for removing arbitrary queued items #168253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

heisenunes
Copy link

There is no way to remove a specific queued SnackBar once it’s been enqueued but not yet displayed (or after it has already dismissed itself). Calling .close() only works on the currently visible SnackBar; attempts to close one further back in the queue throw:

dart
final sb1 = ScaffoldMessenger.of(context).showSnackBar(...);
final sb2 = ScaffoldMessenger.of(context).showSnackBar(...);
final sb3 = ScaffoldMessenger.of(context).showSnackBar(...);
sb2.close(); // throws because sb2 is not the active SnackBar

Technical Impact:

  • Uncaught exceptions when trying to close a non-active snack bar.
  • Poor UX: Unable to cancel outdated or no-longer-relevant messages before they appear.
  • Workarounds required (try/catch, flush entire queue) that are clumsy and break user expectations.
  • Inconsistent API: removeCurrentSnackBar exists for the active item, but nothing for arbitrary queued items.

Fixes #168211

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link

google-cla bot commented May 2, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add removeSnackBar function for removing a specific snackbar from the queue
1 participant