Repository navigation
pushAndRemoveUntil removing initialRoute in navigation stack after upgrading to v1.17 #56688
Copy link
Copy link
Closed
Labels
c: regressionIt was better in the past than it is nowIt was better in the past than it is nowf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
Steps to Reproduce
- Run
flutter create bug. - Replace lib/main.dart with
import 'package:flutter/material.dart';
const homepage = '/';
const pageB = '/pageB';
const pageC = '/pageC';
const pageD = '/pageD';
final routes = <String, WidgetBuilder>{
homepage: (BuildContext context) => Homepage(),
pageB: (BuildContext context) => PageB(),
pageC: (BuildContext context) => PageC(),
pageD: (BuildContext context) => PageD(),
};
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
initialRoute: homepage,
routes: routes,
);
}
}
class Homepage extends StatelessWidget {
const Homepage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Homepage'),
),
body: Center(
child: FlatButton(
child: Text('Go to Page B'),
color: Colors.blue,
onPressed: () {
Navigator.pushNamed(context, pageB);
},
),
),
);
}
}
class PageB extends StatelessWidget {
const PageB({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page B'),
),
body: Center(
child: FlatButton(
child: Text('Go to Page C'),
color: Colors.blue,
onPressed: () {
Navigator.pushNamed(context, pageC);
},
),
),
);
}
}
class PageC extends StatelessWidget {
const PageC({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page C'),
),
body: Center(
child: FlatButton(
child: Text('Go to Page D and remove until Page B'),
color: Colors.blue,
onPressed: () {
Navigator.pushNamedAndRemoveUntil(
context, pageD, ModalRoute.withName(pageB));
},
),
),
);
}
}
class PageD extends StatelessWidget {
const PageD({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page D'),
),
body: Center(
child: FlatButton(
child: Text('Go back to Page B'),
color: Colors.blue,
onPressed: () {
Navigator.pop(context);
},
),
),
);
}
}
- Run app and go until page D then go back to initial page
Expected results:
I'm expecting being able to go back to the initialRoute (homepage)
Actual results:
I'm only able to go back till Page B as calling pushNamedAndRemoveUntil seems to also have removed the initialRoute (homepage)
Logs
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-CN)
• Flutter version 1.17.0 at /Users/christophewang/dev/flutter
• Framework revision e6b34c2b5c (6 days ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/christophewang/Library/Android/sdk
• Platform android-29, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.45.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.1
[✓] Connected device (1 available)
• iPhone Xʀ • AD185E2B-3525-49C1-A434-72B9CB85A2A1 • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: regressionIt was better in the past than it is nowIt was better in the past than it is nowf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Activity
[-][Stable v1.17] pushAndRemoveUntil removing initialRoute in navigation stack[/-][+]pushAndRemoveUntil removing initialRoute in navigation stack after upgrading to v1.17[/+]goderbauer commentedon May 8, 2020
/cc @chunhtai Can you take a look at this regression?
JacobT14 commentedon May 16, 2020
So I can’t say for sure, but thought I would put this on here just in case.
I have a case where on my local simulator the pushAndRemoveUntil works properly, but after it goes through my cicd to qa it doesn’t work. cicd uses the latest from the release branch(1.17.1-Stable according to the build logs), whereas my local is still on 1.17, not sure if I’m on some random iteration on the dev branch. I’ll get more info on Monday when I sit down and figure out what’s going on. But just putting this on here in case it rings any bells to anyone. If I find the cause and it’s an actual issue I’ll create a separate issue for it.
jonathanjuursema commentedon Jul 18, 2020
Edit: This is no longer a problem. We've figured out we were doing something else wrong: we were using a RouteGenerator instead of providing the routes directly into the MainApp. For some reason this caused routes to be pushed with name
null, which is why thepushNamedAndRemoveUntilcall with a route name didn't work properply.Cheers!
Hey! 👋
I'm curious. I think I am encountering the same issue using Flutter 1.17.5.
We have a splash screen (
/) that goes on to our homepage (/home) using the following to prevent going back to the splash screen.From there on we have calls from our drawer and the home page to the following to navigate through the app:
Whenever a button is clicked navigating from the homepage to some other page, and pressing back, the app exits.
From the PR's, the fact this issue is closed and @goderbauer's remark I take it this is a regression that has since been fixed. However, I tried compiling and building the app in
1.17.0(following @JacobT14's comment),1.18.0-13.0.preandmaster, and all of these exhibit the same.Chances are I'm forgetting a step after switching the Flutter version, so I wanted to look into that, but just to be sure, in what version of Flutter (stable or otherwise) should I expect this issue to be not present?
Thanks a lot! 🙌
github-actions commentedon Aug 18, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.