Skip to content

Scope NavigationBar sample ScaffoldMessenger#186533

Open
mvincentong wants to merge 1 commit into
flutter:mainfrom
mvincentong:fix-navigationbar-sample-scaffoldmessenger
Open

Scope NavigationBar sample ScaffoldMessenger#186533
mvincentong wants to merge 1 commit into
flutter:mainfrom
mvincentong:fix-navigationbar-sample-scaffoldmessenger

Conversation

@mvincentong
Copy link
Copy Markdown

Fixes #117155

Issue

The NavigationBar nested navigator sample keeps destination pages inside their own nested Navigator, but those pages still inherited the root ScaffoldMessenger from MaterialApp. Calling ScaffoldMessenger.of(context) from a destination page therefore presented MaterialBanners and SnackBars on the root scaffold instead of the destination scaffold.

Fix

Wrap each DestinationView navigator in its own ScaffoldMessenger, 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.dart
  • git diff --check

Risk

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.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels May 14, 2026
Copy link
Copy Markdown
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 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.

Comment thread examples/api/test/material/navigation_bar/navigation_bar.2_test.dart Outdated
@mvincentong mvincentong force-pushed the fix-navigationbar-sample-scaffoldmessenger branch from bb15b45 to 4cf6660 Compare May 15, 2026 00:50
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 framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant