-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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.found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21Found to occur in 3.21frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: solvedIssue is closed as solvedIssue is closed as solvedteam-frameworkOwned by Framework teamOwned by Framework team
Description
Steps to reproduce
run the demo code and click the button on first page with or without the line "ModalRoute.of(context); "
Expected results
the log result is unchanged no matter whether there is the line; and should be the same as other release of flutter;
Actual results
with the line in 3.19 three lines are printed
flutter: reoute create 1 screen
flutter: reoute create 2 screen
flutter: reoute create 1 screen
in other release of flutter or without that line
flutter: reoute create 1 screen
flutter: reoute create 2 screen
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'Named Routes Demo',
routes: {
'/': route("/"),
'/second': route("/second"),
},
),
);
}
WidgetBuilder route(String name){
return (context) {
ModalRoute.of(context); //this line casue the problem;
if(name == "/"){
return FirstScreen();
}else if(name == "/second"){
return SecondScreen();
}
throw "route not found";
};
}
class FirstScreen extends StatelessWidget {
FirstScreen({super.key}) {
print("reoute create 1 screen");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Screen'),
),
body: Center(
child: ElevatedButton(
// Within the `FirstScreen` widget
onPressed: () {
// Navigate to the second screen using a named route.
Navigator.pushNamedAndRemoveUntil(context, '/second',(a)=>false);
},
child: const Text('Launch screen'),
),
),
);
}
}
class SecondScreen extends StatelessWidget {
SecondScreen({super.key}) {
print("reoute create 2 screen");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body:const Center(
child: Text("second screen"),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[Paste your output here]wanjmTr2eTr2e
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.found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21Found to occur in 3.21frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: solvedIssue is closed as solvedIssue is closed as solvedteam-frameworkOwned by Framework teamOwned by Framework team