此问题一般情况出现在直接在main.dart文件中操作路由。

如上情况提示路由控制器需要一个context但是当前navigator并不包含,通俗的讲要使用路由(Navigator),根控件不能直接是 MaterialApp.

解决方法:将 MaterialApp 内容再使用 StatelessWeight 或 StatefulWeight 包裹一层

void main() async{await setupServiceLocator();/// 微信、QQ注册runApp(MultiProvider(// 状态管理providers: [ChangeNotifierProvider(create: (_) => UserProvider()),],child: MyAppPrepare(),//解决MaterialApp中的跳转路由的context问题));
}///解决MaterialApp中的跳转路由的context问题
class MyAppPrepare extends StatelessWidget {@overrideWidget build(BuildContext context) {return MaterialApp(debugShowCheckedModeBanner: false,builder: (context, widget) {return MediaQuery(///设置文字大小不随系统设置改变data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),child: FlutterEasyLoading(child: widget),);},home: GestureDetector(/// 全局键盘关闭onTap: () {FocusScopeNode focusScopeNode = FocusScope.of(context);if (!focusScopeNode.hasPrimaryFocus &&focusScopeNode.focusedChild != null) {FocusManager.instance.primaryFocus?.unfocus();}},child: MyApp(),),theme: ThemeData(primarySwatch: ColorTool.white),localizationsDelegates: [RefreshLocalizations.delegate,GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate,CupertinoLocalizationsDelegate(),],supportedLocales: [Locale('zh', 'CN')],);}
}class MyApp extends StatefulWidget {@overrideState<StatefulWidget> createState() {return _MyAppState();}static BuildContext getContext() {return _MyAppState.getContext();}
}class _MyAppState extends State<MyApp> with WidgetsBindingObserver{RouteManager _routeDelegate = RouteManager();
static BuildContext appContext;static BuildContext getContext() {return appContext;}@overridevoid initState() {super.initState();//添加观察者,检测页面生命周期WidgetsBinding.instance.addObserver(this);EventBusUtils _event = EventBusUtils.instance;if (CacheManager.shared.prefs != null && CacheManager.shared.getString("isShowAgreement") != null) {_prepareInitIM();}}@overridevoid dispose() {super.dispose();//页面销毁时,移出页面生命周期监听者WidgetsBinding.instance?.removeObserver(this);}@overrideWidget build(BuildContext context) {appContext = context;return FutureBuilder<CacheManager>(future: CacheManager.preInit(context),//进行初始化builder: (BuildContext context, AsyncSnapshot<CacheManager> snapshot) {//定义routevar _widget = (snapshot.connectionState == ConnectionState.done && snapshot.data != null)? Router(routerDelegate: _routeDelegate): snapshot.connectionState != ConnectionState.done? Scaffold(body: Center(child: CircularProgressIndicator(color: ColorTool.red),),):_showAgreementWindow(appContext);return _widget;},);}

flutter报错Navigator operation requested with a context that does not include a Navigator相关推荐

  1. Flutter提示之Navigator operation requested with a context that does not include a Navigator.

    1 .问题 用Flutter写了页面跳转,提示错误如下 Navigator operation requested with a context that does not include a Nav ...

  2. 【错误记录】Flutter 界面跳转报错 ( Navigator operation requested with a context that does not include a Naviga )

    文章目录 一.报错信息 二.问题分析 三.解决方案 一.报错信息 Flutter 界面跳转时 , 报如下错误 : ======== Exception caught by gesture ====== ...

  3. Flutter报错BlocProvider.of() called with a context that does not contain a Bloc of type **.

    Flutter报错BlocProvider.of() called with a context that does not contain a Bloc of type **. 在使用flutter ...

  4. flutter报错Could not connect to lockdownd, error code -

    关于 flutter 报错信息解决方案 第一步: cmd+shift+g 前往 /var/db 文件夹,找到lockdown文件夹,修改读写权限 第二步 : 打开命令行,依次执行 brew updat ...

  5. php7链接数据库报错The server requested authentication method unknown to the client

    php7链接数据库报错The server requested authentication method unknown to the client 主要原因 是因为 mysql 8.0 升级了密码 ...

  6. RedisTemplate报错WRONGTYPE Operation against a key holding the wrong kind of value

    场景 今天写业务代码,先从redis中读取值,不存在的话加redis锁,锁定之后再次尝试读取一次redis,没有值的话去db中读取并写redis缓存. 非常简单的代码,确报错WRONGTYPE Ope ...

  7. SVN报错“previous operation has not finished…“的解决办法

    SVN因多次操作卡死,报错"previous operation has not finished-", 无法进行任何新操作时,可以在SVN的工作目录下打开命令行窗口,输入&quo ...

  8. flutter 报错java.net.URISyntaxException: Illegal character in opaque part at index 2

    记录flutter报错如下错误以及解决办法 FAILURE: Build failed with an exception. * What went wrong: Execution failed f ...

  9. 搭建网站服务器时报错url,服务器网站总报错“ERROR the requested URL could not be retrieved”解决办法...

    服务器网站总报错"ERROR the requested URL could not be retrieved" ERROR The requested URL could not ...

最新文章

  1. git回退commit_Git进阶 温故知新系列
  2. 利用shell监控cpu、磁盘、内存使用率
  3. Python/Anaconda-python2.x代码转为python3.x代码
  4. 与protected成员有关的单元测试方式
  5. [詹兴致矩阵论习题参考解答]习题1.13
  6. C# processbar设置
  7. CAD如何打印出多页PDF保存在一个PDF内
  8. 消息中间件MQ与RabbitMQ
  9. 腾讯qq等级计算公式面试题
  10. 记录自定义维护视图的修改日志
  11. 十大推荐提交的安卓市场
  12. 1+x 云计算平台运维与开发测试题
  13. 将一个大文件分割为若干个小文件的方法
  14. 《Windows游戏编程大师技巧》(第二版)第1章(下)
  15. Python数据分析知识汇总
  16. 轴承故障诊断之时域指标
  17. 非常实用的cmd命令
  18. 衢州计算机编程哪个学校好,柯城教育大盘点||新华小学——打开我们的时光门...
  19. 上行参考信号-SRS
  20. 移动端响应式布局项目之阿里百秀首页

热门文章

  1. 多网卡的 bonding 模式
  2. 工业自动化控制软件scada连接数据库说明
  3. 用python写爬虫,爬取清纯妹子网站
  4. DM培训,考试,以后我也是DBA啦~
  5. 【Proteus仿真】【51单片机】K型热电偶测温系统设计
  6. 史上最详细、最完全的jupyter notebook使用教程,Python使用者必备!——ipython系列之三
  7. ​刘强东卸任京东集团 CEO,徐雷接任;苹果新专利可为多个设备无线充电;Rust公布2024年路线图|极客头条
  8. 数字信号处理基础----xilinx除法器IP使用
  9. 计算机网络:ISO/OSI参考模型和TCP/IP模型
  10. 如何做好MRO工业品采购