Last active
June 11, 2020 07:30
-
-
Save rickyngan/5927c85551f0146fb8c0c5232494ba60 to your computer and use it in GitHub Desktop.
2020 Jun 13 HoC HK Flutter: 7_route_navigator
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