Skip to content

ScaffoldMessenger only shows to root nested Scaffold#74093

Merged
fluttergithubbot merged 5 commits into
flutter:masterfrom
Piinks:rootScaffoldMsgr
Jan 22, 2021
Merged

ScaffoldMessenger only shows to root nested Scaffold#74093
fluttergithubbot merged 5 commits into
flutter:masterfrom
Piinks:rootScaffoldMsgr

Conversation

@Piinks

@Piinks Piinks commented Jan 16, 2021

Copy link
Copy Markdown
Contributor

This change makes it such that when a ScaffoldMessenger has nested Scaffold descendants, it will only show SnackBars on the root Scaffold of the subtree. This will remove the possibility of duplicate SnackBars showing up in the UI in this use case.

This change is courtesy of early customer feedback. :)
See b/171649782

Fixes #69929

Other options discussed were to

  • assert for nested Scaffolds
    • this makes for a really poor experience trying to migrate to the new API. Especially in complex applications, determining the right scopes to create for ScaffoldMessenger & nested Scaffolds is difficult.
  • introduce a ScaffoldMessengerBehavior a la present to root or present to leaf for nested Scaffolds.
    • When evaluating the leaf option, we discovered it would not work properly in some use cases, and could not find a case where it was explicitly required. Since you can close or tighten the scope of the ScaffoldMessenger by instantiating your own further down the tree, having this option seemed unnecessary, with the root option making the most sense for the issue at hand.

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 listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

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

@Piinks Piinks added framework flutter/packages/flutter repository. See also f: labels. a: quality A truly polished experience customer: money (g3) a: layout SystemChrome and Framework's Layout Issues labels Jan 16, 2021
@flutter-dashboard flutter-dashboard Bot added the f: material design flutter/packages/flutter/material repository. label Jan 16, 2021
@google-cla google-cla Bot added the cla: yes label Jan 16, 2021
Comment thread packages/flutter/test/material/snack_bar_test.dart Outdated
@Piinks Piinks requested a review from HansMuller January 16, 2021 01:00
@skia-gold

Copy link
Copy Markdown

Gold has detected about 2 untriaged digest(s) on patchset 1.
View them at https://flutter-gold.skia.org/cl/github/74093

@skia-gold

Copy link
Copy Markdown

Gold has detected about 1 untriaged digest(s) on patchset 2.
View them at https://flutter-gold.skia.org/cl/github/74093

Comment thread packages/flutter/lib/src/material/scaffold.dart Outdated
Comment thread packages/flutter/lib/src/material/scaffold.dart
Comment thread packages/flutter/lib/src/material/scaffold.dart
@xu-baolin xu-baolin self-requested a review January 18, 2021 08:03
@xu-baolin

Copy link
Copy Markdown
Member

Just update your branch can fix the CI checks :)

@skia-gold

Copy link
Copy Markdown

Gold has detected about 2 untriaged digest(s) on patchset 4.
View them at https://flutter-gold.skia.org/cl/github/74093

@flutter-dashboard

Copy link
Copy Markdown

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #74093 at sha c8587dc

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Jan 19, 2021

@HansMuller HansMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

for (final ScaffoldState scaffold in _scaffolds) {
scaffold._updateSnackBar();
if (_isRoot(scaffold))
scaffold._updateSnackBar();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At this point it would be safe to return.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily. There can be other Scaffolds that need to get a SnackBar. For example, on another route. That is how we get the nice hero animation as the SnackBar persists across the transition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. Hopefully there's a test that will catch someone (like me) adding the short-circuit return without realizing the implications

Comment thread packages/flutter/lib/src/material/scaffold.dart Outdated
Comment thread packages/flutter/test/material/snack_bar_test.dart Outdated
Comment thread packages/flutter/test/material/snack_bar_test.dart Outdated
),
));

final ScaffoldMessengerState scaffoldMessengerState = tester.state(

@HansMuller HansMuller Jan 20, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the type parameter: tester.state<ScaffoldMessengerState>(

It's a shame that the same identifier has to be repeated 3x :-(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What is being repeated 3x?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

final ScaffoldMessengerState scaffoldMessengerState = tester.state<ScaffoldMessengerState>(

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread packages/flutter/lib/src/material/scaffold.dart
/// ScaffoldMessenger will only present a [SnackBar] to the root Scaffold of
/// the subtree of Scaffolds. In order to show SnackBars in the inner, nested
/// Scaffolds, set a new scope for your SnackBars by instantiating a new
/// ScaffoldMessenger in between the levels of nesting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

optional: may be nice to show a code sample of that here.

@Piinks Piinks Jan 20, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you think of linking to an example in the gallery? I think this sample would be very large to include inline, and I don't want to encourage nesting scaffolds... there is a section in the Scaffold docs that says nested Scaffolds is not typically necessary. There are a few cases where it is relevant - like in the gallery where there is embedded Flutter content, but the Scaffold docs recommend avoiding nesting.

@skia-gold

Copy link
Copy Markdown

Gold has detected about 1 untriaged digest(s) on patchset 5.
View them at https://flutter-gold.skia.org/cl/github/74093

@flutter-dashboard

Copy link
Copy Markdown

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #74093 at sha 04b33f0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: layout SystemChrome and Framework's Layout Issues a: quality A truly polished experience customer: money (g3) f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ScaffoldMessenger should be more helpful with nested Scaffolds

6 participants