Skip to content

[material_ui] Document and demonstrate safe MaterialBanner dismissal across routes - #13267

Merged
auto-submit[bot] merged 3 commits into
flutter:mainfrom
mmohankrishna-lab:fix-material-banner-dismiss-89705
Nov 13, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:mainfrom
mmohankrishna-lab:fix-material-banner-dismiss-89705

Conversation

@mmohankrishna-lab

@mmohankrishna-lab mmohankrishna-lab commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Updates MaterialBanner.actions and ScaffoldMessengerState.showMaterialBanner documentation and DartPad examples to demonstrate how to safely dismiss a MaterialBanner across routes without looking up a deactivated route's BuildContext:

  • Documents on MaterialBanner.actions and ScaffoldMessengerState.showMaterialBanner that because banners presented by ScaffoldMessenger persist across routes, action callbacks should either capture the ScaffoldMessengerState reference before calling showMaterialBanner or wrap the action widget in a Builder to obtain an active BuildContext.
  • Updates material_banner.1.dart and scaffold_messenger_state.show_material_banner.0.dart so the 'DISMISS' button calls messenger.hideCurrentMaterialBanner instead of onPressed: null.
  • Updates the example tests.

Fixes flutter/flutter#89705

Pre-Review Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 15, 2026
@github-actions github-actions Bot added p: material_ui triage-design Should be looked at in design triage labels Oct 15, 2026
@google-cla

google-cla Bot commented Oct 15, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the MaterialBanner documentation, examples, and tests to demonstrate and verify safe dismissal of banners across routes. Specifically, it captures the ScaffoldMessengerState before showing the banner to ensure the dismiss action does not rely on a deactivated BuildContext. A syntax error was identified in the material_banner.1.dart example where const .all(20) is used instead of const EdgeInsets.all(20).

@mmohankrishna-lab

Copy link
Copy Markdown
Contributor Author

@google-cla rescan

1 similar comment
@mmohankrishna-lab

Copy link
Copy Markdown
Contributor Author

@google-cla rescan

@mmohankrishna-lab
mmohankrishna-lab force-pushed the fix-material-banner-dismiss-89705 branch from f58eb3e to c2df079 Compare October 16, 2026 10:19
@mmohankrishna-lab mmohankrishna-lab self-assigned this Oct 22, 2026

@QuncCccccc QuncCccccc 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.

Thanks for adding the document! Left some comments below.

///
/// Typically this is a list of [TextButton] widgets.
///
/// When a [MaterialBanner] is presented through a [ScaffoldMessenger], it

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.

nit: "persists across routes" only holds when the [ScaffoldMessenger] is above the [Navigator] (for example the one [MaterialApp] creates), and it's the route's [BuildContext] that gets deactivated rather than the route itself. Maybe: "When a [MaterialBanner] is shown by a [ScaffoldMessenger] above the [Navigator], such as the one created by [MaterialApp], it stays visible after the route that showed it is popped, and that route's [BuildContext] is deactivated."

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.

Updated the wording as suggested in 657e3a0. I also applied the same clarification to the related doc on ScaffoldMessengerState.showMaterialBanner in scaffold.dart so the two stay consistent.

expect(tester.getSize(content).isEmpty, isTrue);
});

// Regression test for https://github.com/flutter/flutter/issues/89705.

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.

This is not a regression test. Maybe consider removing it.

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.

since this PR only updates docs and examples and doesn't change behavior. Removed the test in 657e3a0. The safe dismissal pattern is still covered by the example tests.

@QuncCccccc QuncCccccc 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. Thank you!

@mmohankrishna-lab mmohankrishna-lab added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit
auto-submit Bot merged commit 34b89b2 into flutter:main Nov 13, 2026
12 checks passed
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this pull request Nov 13, 2026
…lutter#196558)

Manually rolls flutter/packages from 14f9933a8cd6 to 015df97cbc3f (5
revisions). This is the same one-line change the [flutter/packages →
flutter/flutter
autoroller](https://autoroll.skia.org/r/flutter-packages-flutter-autoroll)
makes.

Today's two automatic rolls, flutter#196527 and flutter#196547, failed on presubmit
jobs that don't use the packages pin (`Windows tool_integration_tests_5`
and `Linux_android_emu android_engine_opengles_tests`). The roller
closed the second one after its roll window ended. It only rolls on
weekdays and doesn't support manual rolls, so its next roll would be on
Monday.

flutter/packages@14f9933...015df97

2026-11-13 [camera_windows] Fall back to temp dir for capture path.
(flutter/packages#12755)
2026-11-13 [video_player] Convert event channel to Swift and Pigeon
(flutter/packages#13375)
2026-11-13 [material_ui] Document and demonstrate safe MaterialBanner
dismissal across routes (flutter/packages#13267)
2026-11-12 [flutter_svg] Add a byte budget for the compiled SVG cache
(flutter/packages#13596)
2026-11-12 Roll Flutter from b98afb5 to 9c427b5 (29 revisions)
(flutter/packages#13636)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: material_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[material_ui] MaterialBanner cannot be dismissed once creation context is deactivated

2 participants