经过navigatorKey的方式app
void main() { runApp(MyApp()); } final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>(); class MyApp extends StatelessWidget { MyApp() { } // This widget is the view.common.root of your application. @override Widget build(BuildContext context) { return MaterialApp( navigatorKey: navigatorKey, ); } }
获取context:less
BuildContext context = navigatorKey.currentState.overlay.context
ide
注意:经过这种方式获取的context在某些状况下须要放在Future.delayed(Duration(seconds: 0)).then((onValue) { });
ui
做者:小学生课表明
连接:https://www.jianshu.com/p/897222522abb
来源:简书
著做权归做者全部。商业转载请联系做者得到受权,非商业转载请注明出处。
code