oma*_*per 5 navigation android-context flutter
我最终使用了静态函数,但我需要进行导航,它给了我一个错误,没有找到上下文的吸气剂,所以我寻找解决方案并找到了 GET 包,但当我尝试使用它时,它给了我另一个错误:
E/flutter ( 6078): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)]
Unhandled Exception: NoSuchMethodError: The method 'push' was called on null.
Run Code Online (Sandbox Code Playgroud)
我的代码:
E/flutter ( 6078): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)]
Unhandled Exception: NoSuchMethodError: The method 'push' was called on null.
Run Code Online (Sandbox Code Playgroud)
创建导航键
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
Run Code Online (Sandbox Code Playgroud)
将其分配给 MaterialApp
MaterialApp(
home: Home(),
navigatorKey: navigatorKey
),
Run Code Online (Sandbox Code Playgroud)
然后通过下面的navigatorKey推送你的路线
navigatorKey.currentState.push(MaterialPageRoute(
builder: (context) => AnotherPage(),
));
Run Code Online (Sandbox Code Playgroud)
或者
navigatorKey.currentState.pushNamed(routeName);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6718 次 |
最近记录: |