Created
July 25, 2020 23:43
-
-
Save Nailik/fbdd20b0273a02f57d6f624ab6917bc6 to your computer and use it in GitHub Desktop.
Navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MaterialApp( | |
title: 'Navigation Basics', | |
home: FirstRoute(), | |
)); | |
} | |
class FirstRoute extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('First Route'), | |
), | |
body: Center( | |
child: RaisedButton( | |
child: Text('Open route'), | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => SecondRoute()), | |
); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class SecondRoute extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Second Route"), | |
), | |
body: Center( | |
child: RaisedButton( | |
onPressed: () { | |
Navigator.pop(context); | |
}, | |
child: Text('Go back!'), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment