Why do we need to push the context of our previous screen in flutter? Would we need this in order to keep track of the previous branch of the tree?
Why this is not working? I want to know the reason why this code is not working.
import 'package:flutter/material.dart';
void main() {
runApp(
FirstRoute(),
);
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Navigation Basics',
home: Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
color: Colors.amberAccent,
child: Text('Open route'),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}),
);
},
),
),
),
);
}
}