Flutter入门疑难杂症:获取全局contex:globalkey

1,创建key
class Global{
static GlobalKey navigatorKey = GlobalKey();
}

2,main.dart中引用key
@override
Widget build(BuildContext context) {
MaterialApp app = MaterialApp(
navigatorKey: RouteUtil.navigatorKey,
routes: {

}
}

3,全局使用
Global.navigatorKey.currentState.context
或者
Global.navigatorKey.currentContext

你可能感兴趣的:(Flutter入门)