这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@QuncCccccc
Copy link
Contributor

@QuncCccccc QuncCccccc commented Jul 31, 2025

Fixes #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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jul 31, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@QuncCccccc QuncCccccc requested a review from chunhtai July 31, 2025 23:23
@QuncCccccc QuncCccccc marked this pull request as ready for review July 31, 2025 23:23
Copy link
Contributor

@victorsanni victorsanni left a 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;
Copy link
Contributor

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.

Copy link
Contributor Author

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 :) ?

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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:)

@QuncCccccc QuncCccccc force-pushed the make_snack_bar_dismissible branch from 883566c to f81edef Compare August 12, 2025 21:15
this.showCloseIcon,
this.closeIconColor,
this.duration = _snackBarDisplayDuration,
this.persist = false,
Copy link
Contributor

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.

@QuncCccccc QuncCccccc force-pushed the make_snack_bar_dismissible branch 2 times, most recently from 973b93b to 6991c52 Compare August 19, 2025 21:05

/// 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
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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;

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@github-actions github-actions bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels Aug 19, 2025
@QuncCccccc QuncCccccc changed the title Make SnackBar dismissible after timeout SnackBar with action no longer auto-dismiss Aug 19, 2025
@QuncCccccc
Copy link
Contributor Author

Migration guide: flutter/website#12329

Copy link
Contributor

@chunhtai chunhtai left a 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

sfshaza2 added a commit to flutter/website that referenced this pull request Aug 25, 2025
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>
@QuncCccccc QuncCccccc force-pushed the make_snack_bar_dismissible branch from f1aead3 to fa5a52f Compare August 26, 2025 18:24
@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 26, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 26, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 26, 2025

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.

@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Aug 27, 2025
Merged via the queue into flutter:master with commit 264223d Aug 27, 2025
79 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 27, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 28, 2025
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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 28, 2025
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
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.
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
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.
Jaineel-Mamtora pushed a commit to Jaineel-Mamtora/flutter_forked that referenced this pull request Sep 24, 2025
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.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos 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.

[VPAT][A11y] snackbar with action should not time out by default

3 participants