Created
May 24, 2020 15:43
-
-
Save iampato/119b81942aef817838e7d194a0382096 to your computer and use it in GitHub Desktop.
Navigating using scaffold key
This file contains hidden or 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
class FirstPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Material( | |
child: Center(child: Text("First Page")), | |
); | |
} | |
} |
This file contains hidden or 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
class MyHomePage extends StatelessWidget { | |
final GlobalKey<ScaffoldState> _scaffoldkey = new GlobalKey<ScaffoldState>(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
key: _scaffoldkey, | |
appBar: AppBar( | |
title: Text("Example"), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
RaisedButton( | |
child: Text("Go to 1st"), | |
onPressed: () => Navigator.push( | |
_scaffoldkey.currentContext, | |
MaterialPageRoute( | |
builder: (_) => FirstPage(), | |
), | |
), | |
), | |
RaisedButton( | |
child: Text("Go to 2st"), | |
onPressed: () => Navigator.push( | |
_scaffoldkey.currentContext, | |
MaterialPageRoute( | |
builder: (_) => SecondPage(), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
This file contains hidden or 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
class SecondPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Material( | |
child: Center(child: Text("Second Page")), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment