Skip to content

Instantly share code, notes, and snippets.

@junsuk5
Created May 16, 2019 10:17
Show Gist options
  • Save junsuk5/eb802dccf608188bb077723a7cf8e53e to your computer and use it in GitHub Desktop.
Save junsuk5/eb802dccf608188bb077723a7cf8e53e to your computer and use it in GitHub Desktop.
GlobalKey 사용 예
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