-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
base: master
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a crack at this. Could you also add something to the docs of SnackbarFeatureController.close that points to your new method, so that people can find it? And actually, could you add something to the error message that is thrown when .close
is called and not active?
), | ||
); | ||
|
||
// Trigger both snackBars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Periods at the ends of these sentences here and below.
messenger.removeSnackBar(controller); | ||
|
||
// It should go away immediately | ||
await tester.pumpAndSettle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a single pump
to show that it goes away after a single frame?
@@ -480,6 +480,23 @@ class ScaffoldMessengerState extends State<ScaffoldMessenger> with TickerProvide | |||
hideCurrentSnackBar(); | |||
} | |||
|
|||
/// Removes the given [SnackBar] from the queue, or dismisses it | |||
/// immediately if it’s currently visible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a "See also" that points to SnackbarFeatureController.close?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution!
@@ -3401,4 +3418,4 @@ class _ScaffoldScope extends InheritedWidget { | |||
bool updateShouldNotify(_ScaffoldScope oldWidget) { | |||
return hasDrawer != oldWidget.hasDrawer; | |||
} | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: there should be a newline at EOF
void removeSnackBar( | ||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> controller, | ||
) { | ||
// 1. If it’s queued, drop it before showing: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this assert that the snackbar is in the queue at all?
@@ -3572,4 +3656,4 @@ class _CustomPageRoute<T> extends PageRoute<T> { | |||
) { | |||
return child; | |||
} | |||
} | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too
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:
Fixes #168211
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.