Repository navigation
Closed
flutter/packages
#13397Labels
P2Important issues not at the top of the work listfound in release: 3.29Found to occur in 3.29found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue
Description
Steps to Reproduce
- Run
flutter create bug. - Replace contents of
main.dartfile with the following:
import 'package:flutter/cupertino.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoApp(
title: 'Flutter Demo',
home: MyHomePage(),
routes: {
'/another-page': (context) => AnotherPage(),
},
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: const Icon(CupertinoIcons.map),
label: 'Page 1',
),
BottomNavigationBarItem(
icon: const Icon(CupertinoIcons.map),
label: 'Page 2',
),
BottomNavigationBarItem(
icon: const Icon(CupertinoIcons.map),
label: 'Page 3',
),
],
),
tabBuilder: (context, i) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page $i'),
),
child: SafeArea(
child: Center(
child: Container(
width: double.infinity,
height: 200,
child: Column(
children: [
Text('Hello from Page $i!'),
CupertinoButton(
child: Text('Go to another page'),
onPressed: () =>
Navigator.of(context).pushNamed('/another-page'),
),
],
),
),
),
),
);
},
);
}
}
class AnotherPage extends StatelessWidget {
const AnotherPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
print(ModalRoute.of(context)!.canPop);
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
leading: CupertinoNavigationBarBackButton(
color: CupertinoColors.black,
),
middle: Text('Another Page'),
),
child: Center(
child: Text('Hello from Another Page!'),
),
);
}
}
Run on iOS and click the button to go to Another Page.
Expected results: CupertinoNavigationBarBackButton works normally because the page where it's used indeed can pop.
Actual results: You will see the red box error on page transitions (back and forward) and the following message in the logs:
flutter: true
======== Exception caught by widgets library =======================================================
The following assertion was thrown building CupertinoNavigationBarBackButton(dirty):
CupertinoNavigationBarBackButton should only be used in routes that can be popped
'package:flutter/src/cupertino/nav_bar.dart':
Failed assertion: line 1312 pos 9: 'currentRoute?.canPop == true'
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
CupertinoNavigationBarBackButton file:///%PATH_TO_PROJECT%/lib/main.dart:81:18
When the exception was thrown, this was the stack:
#2 CupertinoNavigationBarBackButton.build (package:flutter/src/cupertino/nav_bar.dart:1312:9)
#3 StatelessElement.build (package:flutter/src/widgets/framework.dart:4648:28)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)
#5 Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)
#6 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4553:5)
...
====================================================================================================
- Output of
flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.2 20G95 darwin-arm, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[!] Android Studio (version 2020.3)
✗ Unable to find bundled Java version.
[✓] VS Code (version 1.60.0)
[✓] Connected device (3 available)
! Doctor found issues in 1 category.
Reacted by Chien
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listfound in release: 3.29Found to occur in 3.29found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue
Activity
danagbemava-nc commentedon Sep 13, 2021
Issue is reproducible on latest
stableandmaster.logs
flutter doctor -v
TahaTesser commentedon Oct 4, 2021
Used the following minimal code sample
complete minimal runnable code sample
I just dug deeper into this, the main exception is thrown because when implementing
CupertinoNavigationBarBackButtonbecausecurrentRoute?.canPopis temporarily returned null during the transition withCupertinoNavigationBarBackButtonmain.dart
nav_bar.dart
Initially
currentRoute?.canPopit returns true > null > true againLogs
Now try commenting
CupertinoNavigationBarBackButton,currentRoute?.canPopdoesn't go null anymoremain.dart
Logs
CC: @chunhtai
I see that you've worked on improving
canPoplogic in this PR #73993 which also includes a test forCupertinoNavigationBarBackButton. Do you've any hints as to where we can fix this? I would love to help.ynnob commentedon Jan 20, 2023
I think this is still not fixed.
Breaks when we navigate from a CupertinoPageScaffold page to a second CupertinoPageScaffold that implements a
CupertinoNavigationBarBackButton. If you remove the CupertinoNavigationBarBackButton or add a manual onPressed method that will pop the navigation stack it will work and no assertion error is thrown.Also if you navigate from a normal Scaffold to the CupertinoPageScaffold that implements
CupertinoNavigationBarBackButtonit will work. it only seems to break when the calling page is also a CupertinoPageScaffold.Error:
erkinovalim commentedon May 4, 2025
Is there a solution for this yet??? I am also facing this problem
1 remaining item
flutter-triage-bot commentedon May 4, 2025
This issue is missing a priority label. Please set a priority label when adding the
triaged-designlabel.[-]CupertinoNavigationBarBackButton works incorrectly[/-][+]CupertinoNavigationBarBackButton crashes[/+]tirth-patel-nc commentedon May 15, 2025
Triage Report
I was able to reproduce the issue using the provided code sample on both the
stable (3.29.3)andmaster (3.33.0-1.0.pre.83)channels.Screen.Recording.2025-05-15.at.8.50.42.PM.mov
Simulator.Screen.Recording.-.iPhone.16.Plus.-.2025-05-15.at.20.52.41.mp4
Error Log
Code Sample
stable (3.29.3) - flutter doctor -v
master (3.33.0-1.0.pre.83) - flutter doctor -v
[cupertino_ui] Fix CupertinoNavigationBarBackButton assertion debug (f…