I can already take an argument from the navigator. this is the code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
"/": (_) => Screen1(),
"/2": (_) => Screen2(),
},
);
}
}
class Screen1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () =>
Navigator.of(context).pushNamed("/2", arguments: "test"),
),
);
}
}
class Screen2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
final String param = ModalRoute.of(context).settings.arguments;
print("This function is called when navigator poped");
return Scaffold(
body: Center(
child: InkWell(
onTap: () => Navigator.of(context).pop(), child: Text(param)),
),
);
}
}
I don't want the build function to be called when the navigator is pop. I know if something has changed in the navigator, it will call the build function again. but I want that not to happen. how to pop to screen1 without calling build function of Screen2?