Repository navigation
[material_ui] Document and demonstrate safe MaterialBanner dismissal across routes - #13267
Conversation
|
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. |
There was a problem hiding this comment.
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).
|
@google-cla rescan |
1 similar comment
|
@google-cla rescan |
f58eb3e to
c2df079
Compare
QuncCccccc
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
This is not a regression test. Maybe consider removing it.
There was a problem hiding this comment.
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.
…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)
Updates
MaterialBanner.actionsandScaffoldMessengerState.showMaterialBannerdocumentation and DartPad examples to demonstrate how to safely dismiss aMaterialBanneracross routes without looking up a deactivated route'sBuildContext:MaterialBanner.actionsandScaffoldMessengerState.showMaterialBannerthat because banners presented byScaffoldMessengerpersist across routes, action callbacks should either capture theScaffoldMessengerStatereference before callingshowMaterialBanneror wrap the action widget in aBuilderto obtain an activeBuildContext.material_banner.1.dartandscaffold_messenger_state.show_material_banner.0.dartso the'DISMISS'button callsmessenger.hideCurrentMaterialBannerinstead ofonPressed: null.Fixes flutter/flutter#89705
Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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