Scope NavigationBar sample ScaffoldMessenger#186533
Open
mvincentong wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request wraps the nested Navigator in a ScaffoldMessenger within the navigation_bar.2.dart example, ensuring that SnackBars and MaterialBanners are displayed within the destination scope. A new test case verifies that MaterialBanners are positioned correctly below the destination's AppBar. Feedback suggests improving test robustness by explicitly asserting the presence of the AppBar widget before accessing its BuildContext.
bb15b45 to
4cf6660
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #117155
Issue
The
NavigationBarnested navigator sample keeps destination pages inside their own nestedNavigator, but those pages still inherited the rootScaffoldMessengerfromMaterialApp. CallingScaffoldMessenger.of(context)from a destination page therefore presentedMaterialBanners andSnackBars on the root scaffold instead of the destination scaffold.Fix
Wrap each
DestinationViewnavigator in its ownScaffoldMessenger, matching the nested scaffolds owned by that navigator. This keeps destination-scoped scaffold features inside the selected destination while preserving the existing nested navigator routing behavior.Tests
./bin/flutter test examples/api/test/material/navigation_bar/navigation_bar.2_test.dart --plain-name 'RootPage presents material banners below the destination app bar'failed before the fix and passed after it./bin/flutter test examples/api/test/material/navigation_bar/navigation_bar.2_test.dart./bin/flutter analyze examples/api/lib/material/navigation_bar/navigation_bar.2.dart examples/api/test/material/navigation_bar/navigation_bar.2_test.dart./bin/dart format --output=none --set-exit-if-changed examples/api/lib/material/navigation_bar/navigation_bar.2.dart examples/api/test/material/navigation_bar/navigation_bar.2_test.dartgit diff --checkRisk
Changed files: one API sample and its existing focused test. The change only scopes scaffold messenger lookup for each nested destination navigator; route generation, destination persistence, dialogs, and bottom-sheet behavior remain unchanged.