-
Notifications
You must be signed in to change notification settings - Fork 29.5k
SnackBar with action no longer auto-dismiss #173084
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
SnackBar with action no longer auto-dismiss #173084
Conversation
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.
Code Review
This pull request correctly implements the dismissible property for SnackBar to control whether it dismisses after a timeout. The implementation is straightforward, and the new functionality is well-covered by a new test case. I've found one minor issue with a leftover debug print statement that should be removed.
victorsanni
left a comment
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.
I'm wondering if the default behavior of a Snackbar with an action still timing out should be kept. Although changing the default will be a breaking change.
| /// | ||
| /// Defaults to true. If false, the snack bar is still there even after the | ||
| /// timeout, unless the user taps the action button or the close icon. | ||
| final bool dismissible; |
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.
Not sure if dismissible is the right term, since tapping the action button dismisses the snackbar even when dismissible is false. I think the timeout vs. non-timeout is what makes this API distinctive.
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 helping review the change! Then maybe dismissAfterTimeout or autoDismiss? I'm bad at naming. Any better names are welcome!
I'm wondering if the default behavior of a Snackbar with an action still timing out should be kept.
The main concern is the breaking change. If we change the default, we might need to inform developers to change all existing use cases. Just checked the specs on M3 website, it mentioned auto-dismiss though. Maybe we can disable the auto-dismiss if action/close icon is not null? WDYT @victorsanni @chunhtai :) ?
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.
Any better names are welcome!
Maybe something like canTimeout or shouldTimeout?
Maybe we can disable the auto-dismiss if action/close icon is not null?
The spec says "Snackbars with actions should remain on the screen until the user takes an action on the snackbar, or dismisses it." So we might have to change the default and inform developers. I opened #173127 to check how bad the breaking change will be.
But irrespective of that I think the new API is definitely useful.
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.
I'm confused by the spec. I read through it and in some places it suggests that the snackbar always dismisses by itself, even with an action. Maybe there's someone material to clarify?
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 persist?
If the spec is contradicting itself, you can file an issue using the template from here https://buganizer.corp.google.com/issues/394084228
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.
Filed a ticket: b/438264879
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.
I just renamed the property and will wait for responses from the material team:)
883566c to
f81edef
Compare
| this.showCloseIcon, | ||
| this.closeIconColor, | ||
| this.duration = _snackBarDisplayDuration, | ||
| this.persist = false, |
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.
What if developer wants it to not persist, but talkback is on? I think this may need to be nullable and if it is null, we can derive it from either action not null or accessibleNavigation is on. If it is set, we should respect it no matter what.
973b93b to
6991c52
Compare
|
|
||
| /// Whether the snack bar will stay or auto-dismiss after timeout. | ||
| /// | ||
| /// If true, the snack bar is still there even after the timeout, until the |
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 remains displayed or remains visible? To be more descriptive.
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.
Done
| /// If true, the snack bar is still there even after the timeout, until the | ||
| /// user taps the action button or the close icon. If false, the snack bar | ||
| /// will be dismissed after the timeout. If this is null but the snackbar | ||
| /// action is not null, the snackbar will persist as well. |
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.
Since we are not relying on screen reader on/off. We can make this non-null and do something like
SnackBar(
bool? persist
): this.persist = perisit ?? action != null;
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.
this will mean snackbar with action never auto-dismisses. which is a breaking change. Is this intended?
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.
yes, since this is the material guideline, we should make it the default and communicate to the developer.
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.
I wasn't too sure before because I was waiting for material team's response, but now they do. so we should go with this breaking change
| /// | ||
| /// If true, the snack bar is still there even after the timeout, until the | ||
| /// user taps the action button or the close icon. If false, the snack bar | ||
| /// will be dismissed after the timeout. If this is null but the snackbar |
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
If not provided, this is set to true if [action] is not null
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.
also consider separate each if sentence into a new paragraph for readability
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.
Done
SnackBar dismissible after timeout|
Migration guide: flutter/website#12329 |
chunhtai
left a comment
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.
LGTM, just one minor comment
This PR is to add a breaking change page for flutter/flutter#173084 ## Presubmit checklist - [x] If you are unwilling, or unable, to sign the CLA, even for a _tiny_, one-word PR, please file an issue instead of a PR. - [ ] If this PR is not meant to land until a future stable release, mark it as draft with an explanation. - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style)—for example, it doesn't use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first-person pronouns). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: Shams Zakhour <44418985+sfshaza2@users.noreply.github.com>
f1aead3 to
fa5a52f
Compare
|
autosubmit label was removed for flutter/flutter/173084, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@c65f01d...da5523a 2025-08-27 dacoharkes@google.com [native assets] Roll dependencies (flutter/flutter#174522) 2025-08-27 engine-flutter-autoroll@skia.org Roll Skia from 8cf2faada2b5 to 7e6da45059c5 (5 revisions) (flutter/flutter#174523) 2025-08-27 43054281+camsim99@users.noreply.github.com [Android] Restrict AOT shared library engine flag to trusted paths (flutter/flutter#173359) 2025-08-27 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from L5zGzsIWIS8N36AFQ... to bHYRvLv2Dg56RWZF2... (flutter/flutter#174518) 2025-08-27 engine-flutter-autoroll@skia.org Roll Packages from 1ef712e to 86fbeec (7 revisions) (flutter/flutter#174521) 2025-08-27 engine-flutter-autoroll@skia.org Roll Skia from 448a0d0e57e3 to 8cf2faada2b5 (1 revision) (flutter/flutter#174510) 2025-08-27 engine-flutter-autoroll@skia.org Roll Skia from 4703976a4dae to 448a0d0e57e3 (3 revisions) (flutter/flutter#174494) 2025-08-27 sokolovskyi.konstantin@gmail.com Fix SliverMainAxisGroup and SliverCrossAxisGroup gestures' local positions. (flutter/flutter#174265) 2025-08-27 robert.ancell@canonical.com Fix lock up when window resized with merged UI and platform threads. (flutter/flutter#172893) 2025-08-27 engine-flutter-autoroll@skia.org Roll Skia from dc2872de506f to 4703976a4dae (1 revision) (flutter/flutter#174489) 2025-08-27 engine-flutter-autoroll@skia.org Roll Dart SDK from db45c0ce46f9 to 89023922f96d (2 revisions) (flutter/flutter#174481) 2025-08-27 32538273+ValentinVignal@users.noreply.github.com Migrate examples and defaults to `WidgetState` (flutter/flutter#174421) 2025-08-27 engine-flutter-autoroll@skia.org Roll Skia from 8e48b9e6d67b to dc2872de506f (7 revisions) (flutter/flutter#174479) 2025-08-27 36861262+QuncCccccc@users.noreply.github.com SnackBar with action no longer auto-dismiss (flutter/flutter#173084) 2025-08-26 engine-flutter-autoroll@skia.org Roll Dart SDK from 9054cd8af73c to db45c0ce46f9 (1 revision) (flutter/flutter#174438) 2025-08-26 engine-flutter-autoroll@skia.org Roll Skia from f941bfab7c09 to 8e48b9e6d67b (4 revisions) (flutter/flutter#174468) 2025-08-26 matanlurey@users.noreply.github.com Fix bug in test_golden_comparator, add an e2e test. (flutter/flutter#174459) 2025-08-26 matt.boetger@gmail.com fix typo in test_profile/README.md (flutter/flutter#174384) 2025-08-26 matanlurey@users.noreply.github.com Remove CP labels on not-merged PRs, and explain why (flutter/flutter#174448) 2025-08-26 1063596+reidbaker@users.noreply.github.com Increase testing coverage and maintainability of android manifest parsing logic (flutter/flutter#174070) 2025-08-26 1961493+harryterkelsen@users.noreply.github.com [web] Add test that pictures are not rasterized when clipped out (flutter/flutter#174452) 2025-08-26 engine-flutter-autoroll@skia.org Roll Skia from 538260c45b4a to f941bfab7c09 (3 revisions) (flutter/flutter#174450) 2025-08-26 30870216+gaaclarke@users.noreply.github.com fixes the vulkan image layout transitions for mipmap generation (flutter/flutter#173884) 2025-08-26 15619084+vashworth@users.noreply.github.com Move flakey iOS tests to bringup (flutter/flutter#174446) 2025-08-26 30870216+gaaclarke@users.noreply.github.com [Impeller] Make sure inline passes always do a clear action. (flutter/flutter#174083) 2025-08-26 engine-flutter-autoroll@skia.org Roll Skia from 21214d63fc40 to 538260c45b4a (2 revisions) (flutter/flutter#174441) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Fixes flutter#173000 This PR updated the default behavior for Snackbar with action: * SnackBars no longer auto-dismiss if SnackBar.action is not null. * To override the default behavior, this PR added a property `persist` for `SnackBar`. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
Fixes flutter#173000 This PR updated the default behavior for Snackbar with action: * SnackBars no longer auto-dismiss if SnackBar.action is not null. * To override the default behavior, this PR added a property `persist` for `SnackBar`. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
Fixes flutter#173000 This PR updated the default behavior for Snackbar with action: * SnackBars no longer auto-dismiss if SnackBar.action is not null. * To override the default behavior, this PR added a property `persist` for `SnackBar`. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
Fixes #173000
This PR updated the default behavior for Snackbar with action:
persistforSnackBar.Pre-launch Checklist
///).