Created
May 16, 2019 10:17
-
-
Save junsuk5/eb802dccf608188bb077723a7cf8e53e to your computer and use it in GitHub Desktop.
GlobalKey 사용 예
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 MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final navigatorKey = GlobalKey<NavigatorState>(); // 여기 | |
return MaterialApp( | |
navigatorKey: navigatorKey, // 여기 | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter Tutorial'), | |
), | |
body: Home(), | |
floatingActionButton: FloatingActionButton(onPressed: () { | |
navigatorKey.currentState.push(MaterialPageRoute(builder: (context) => SecondRoute())); // 여기 | |
}), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment