I'm trying to get the app below to print Build on the return to the main page from one of the other pages.
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
initialRoute: '/Home',
routes: {
'/Home': (context) => Home(),
'/First': (context) => First(),
'/Second': (context) => Second(),
},
),);
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
void initState() {
super.initState();
print('Initialisation');
}
@override
Widget build(BuildContext context) {
print('Build');
return Scaffold(
appBar: AppBar(title: Text('Homepage')),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pushNamed(context, '/First');
},
child: Text('Move to the first page'),
),
),
);
}
}
class First extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('First')),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pushNamedAndRemoveUntil(context, '/Second', ModalRoute.withName('/Home'));
},
child: Text('Move to the second page'),
),
),
);
}
}
class Second extends StatefulWidget {
@override
_SecondState createState() => _SecondState();
}
class _SecondState extends State<Second> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Second')),
);
}
}
Right now I am considering that maybe the leading aspect of the AppBar() widget can be edited such that this can happen but I'm really not sure.
I would be very grateful for your time and any suggestions that you might have.