Skip to content

[cupertino_ui] Fix CupertinoNavigationBarBackButton assertion debug - #13397

Merged
auto-submit[bot] merged 3 commits into
flutter:mainfrom
mahaamimran:fix-back-button-flight-assertion
Nov 19, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:mainfrom
mahaamimran:fix-back-button-flight-assertion

Conversation

@mahaamimran

Copy link
Copy Markdown
Contributor

Fixes the debug assertion thrown by CupertinoNavigationBarBackButton when it is passed manually as a CupertinoNavigationBar's leading widget and a page is pushed.

During the push, the navigation bar transition builds another copy of the leading widget in the Navigator's overlay, outside of any route. There ModalRoute.of(context) is null, so currentRoute?.canPop ?? false was false and the assertion failed. The assertion will also now pass when the widget has a _NavigationBarTransition ancestor. It still fires outside any route and in a route that cannot be popped.

Fixes flutter/flutter#89888

Validation

  • flutter analyze (no issues)
  • dart format (no changes)
  • flutter test in packages/cupertino_ui (all passing)
  • The new test in nav_bar_test.dart fails without the change and passes with it.

cupertino_ui uses batch release, so this adds a pending_changelogs entry instead of editing CHANGELOG.md or pubspec.yaml.

Before and after

The new test, run on main without the change and then with it:

Before (fails)
CupertinoNavigationBarBackButton in leading does not assert during the navigation bar transition
The following TestFailure was thrown running a test:
Expected: null
  Actual: _AssertionError:<'package:cupertino_ui/src/nav_bar.dart': Failed assertion: line 2309 pos 9:
'currentRoute?.canPop ?? false': CupertinoNavigationBarBackButton should only be used in routes
that can be popped>
After (passes)
CupertinoNavigationBarBackButton in leading does not assert during the navigation bar transition
All tests passed!

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

@github-actions github-actions Bot added p: cupertino_ui triage-design Should be looked at in design triage labels Oct 23, 2026
@google-cla

google-cla Bot commented Oct 23, 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 assertion in CupertinoNavigationBarBackButton to allow it to be built during a navigation bar transition by checking for a _NavigationBarTransition ancestor widget. It also adds a widget test to verify this behavior and includes a changelog entry. There are no review comments, and I have no feedback to provide.

@mahaamimran
mahaamimran force-pushed the fix-back-button-flight-assertion branch from 928ee85 to d1f6ce3 Compare October 23, 2026 06:00
@QuncCccccc
QuncCccccc requested a review from dkwingsmt November 3, 2026 22:36
dkwingsmt
dkwingsmt previously approved these changes Nov 19, 2026

@dkwingsmt dkwingsmt 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 for the fix!

@dkwingsmt
dkwingsmt requested a review from pjkammer November 19, 2026 07:00
@dkwingsmt dkwingsmt added the CICD Run CI/CD label Nov 19, 2026
@github-actions github-actions Bot added the P2 Important issues not at the top of the work list label Nov 19, 2026

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

I tested the fix in both directions, and it works as expected. The new regression test covers pushing a page, but I also verified that popping back during the transition triggers the same assertion without the fix and passes with it.

Would it be worth adding a regression test for the pop direction as well, so both cases are covered?

@dkwingsmt

Copy link
Copy Markdown
Contributor

@theprantadutta Thank you very much for verifying it! Testing pop would be a valuable add if @mahaamimran has the opportunity.

@mahaamimran

Copy link
Copy Markdown
Contributor Author

Thanks @theprantadutta for testing both directions, and @dkwingsmt for the review! Good call. I’ll add a regression test for the pop direction and push it shortly.

pjkammer
pjkammer previously approved these changes Nov 19, 2026
@mahaamimran
mahaamimran dismissed stale reviews from pjkammer and dkwingsmt via 695abe4 November 19, 2026 18:41
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 19, 2026

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

Thank you!

@dkwingsmt
dkwingsmt requested a review from pjkammer November 19, 2026 18:44
@dkwingsmt dkwingsmt added the CICD Run CI/CD label Nov 19, 2026
@mahaamimran

Copy link
Copy Markdown
Contributor Author

The pop-direction test is now pushed (695abe4). It fails with the same assertion without the fix and passes with it. @dkwingsmt could you take another look when you have a chance? Thanks!

@pjkammer pjkammer added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
@auto-submit
auto-submit Bot merged commit 3be6ef9 into flutter:main Nov 19, 2026
14 checks passed
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-flutter__flutter that referenced this pull request Nov 20, 2026
…er#197056)

flutter/packages@81b7c44...898818d

2026-11-20 [email protected] [material_ui] Use correct time format for
Sinhala locale (flutter/packages#13645)
2026-11-20 [email protected] [material_ui]
Fix showModalBottomSheet safe area on display-feature sub-screens
(flutter/packages#13428)
2026-11-20 [email protected] [material_ui]
Fix M3 doc errors in the `ElevatedButton` and `FilledButton`
(flutter/packages#13685)
2026-11-19 [email protected] [video_player] Convert implementation
to Kotlin (flutter/packages#13683)
2026-11-19 [email protected] [flutter_svg] Add
SvgLoader.provideSvgInIsolate for unsendable loaders
(flutter/packages#13598)
2026-11-19 [email protected] [VPAT] Expose modal drawers with the
dialog semantics role (flutter/packages#13660)
2026-11-19 [email protected] [VPAT] Keep a11y_assessments tooltips
open while hovered (flutter/packages#13657)
2026-11-19 [email protected] [flutter_svg] Stabilize network SVG cache
keys (flutter/packages#13597)
2026-11-19 [email protected]
[image_picker_ios] Return an error instead of an empty file when an
image cannot be saved (flutter/packages#12998)
2026-11-19 [email protected] [cupertino_ui]
Fix CupertinoNavigationBarBackButton assertion debug
(flutter/packages#13397)
2026-11-19 [email protected] [go_router] Document when
GoRouterState.name and path are null (flutter/packages#13486)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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: cupertino_ui P2 Important issues not at the top of the work list triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CupertinoNavigationBarBackButton crashes

4 participants