1 、问题

用Flutter写了页面跳转,提示错误如下

Navigator operation requested with a context that does not include a Navigator.

2 、我的代码

void main() {runApp(MyApp1());
}class MyApp1 extends StatelessWidget {@overrideWidget build(BuildContext context) {return MaterialApp(title: 'open url',home: Scaffold(appBar: AppBar(title: Text('hello flutter'),),body: Column(mainAxisAlignment: MainAxisAlignment.center,mainAxisSize: MainAxisSize.min,children: <Widget>[FlatButton(child: Text("go to new page"),textColor: Colors.blue,onPressed: () {Navigator.push(context, MaterialPageRoute(builder:(context) => NewPage()));},),],),),);}
}class NewPage extends StatelessWidget {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text("hello word"),),body: Center(child: Text("this is new page"),),);}
}

3、原因

Navigator operation requested with a context that does not include a Navigator.

说明这个context上下文不一致,我们看下Navigator的继承关系

class Navigator extends StatefulWidget {
}

但是我的代码是这样的

class MyApp1 extends StatelessWidget {
}

我们需要使用StatefulWidget的Context

4、解决办法

void main() {runApp(MaterialApp(title: "Navigation basics",home: MyApp1(),));
}

用MaterialApp启动

class MaterialApp extends StatefulWidget {
***
}

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

    此问题一般情况出现在直接在main.dart文件中操作路由. 如上情况提示路由控制器需要一个context但是当前navigator并不包含,通俗的讲要使用路由(Navigator),根控件不能直接是 ...

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

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

  3. flutter异常:unsupport operation:Platform._operatingSystem问题

    unsupport operation:Platform._operatingSystem 不支持的操作:操作系统? 应该是Platform._operatingSystem获取到一个系统的值,在代码 ...

  4. keepalived启动后无法ping通VIP,提示ping: sendmsg: Operation not permitted

    主备服务器的keepalived服务启动后,主机上的VIP已经绑定了VIP: 但是ping VIP 提示ping: sendmsg: Operation not permitted错误,如下: 解决方 ...

  5. 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 ...

  6. flutter 弹框 dialog,flutter提示框

    更多文章请查看 lutter从入门 到精通 # flutter dialog 在这里简述flutter dialog 的三种弹出方式 AlertDialog SimpleDialog Cupertio ...

  7. Rplidar 报错提示:Error, operation time out. RESULT_OPERATION_TIMEOUT!

    当Rplidar雷达突然报错: Error, operation time out. RESULT_OPERATION_TIMEOUT! [rplidarNode-2] process has die ...

  8. MFC提示this application has requested the runtime to terminate it in an unusual way editbox框已经删了还在使用

    这个提示让人不知道怎么办? 有代码就好弄,找到出错点.注释,直到没有出错.再一步步缩小范围.最后发现界面上已经删了这个框,代码里还有调用导致的.

  9. Vmware提示:the operation was canceled by the user

    一般遇到这种情况是由于当前虚拟机资源中的资源文件被其他进程占用导致的.如果你的系统中有 DAEMON Tools Lite 软件,那么多半是因为这个原因.因此下面针对此情况提出两种解决办法: 1. 检 ...

最新文章

  1. (Prototype)原型模式的Java实现(转)
  2. 闲鱼如何建设技术舆情治理体系 (多图多代码)
  3. 不能启动u盘 uefi_不知道怎么进入主板设置U盘启动,试试这些方式
  4. MFC开发IM-第十一篇、MFC设置对话框的背景颜色及设置透明
  5. 五种MATLAB画圆方式程序
  6. 安装FeHelper插件
  7. 机器学习 泛化误差和偏差-方差
  8. html泰勒展开,【转载】泰勒展开式
  9. 华为:围绕价值创造展开人力资源管理
  10. 洛谷-P1427-小鱼的数字游戏
  11. 逻辑上的“谬误”真的是我们应该所认为的错误吗?
  12. 解决中标麒麟QQ乱码和WPS缺失字体的错误
  13. Feburary——1052.爱生气的书店老板
  14. includes() 方法
  15. 淘宝/天猫获得商品评论接口
  16. 解决原先mysql与wampserver中mysql冲突问题
  17. 机器人强化学习——Comparing Task Simplifications to Learn Closed-Loop Object Picking Using DRL(2019 RAL)
  18. SQL Server连接其他服务器
  19. 1000以内的“完数”
  20. pps抽样matlab,抽样器,sampler,在线英语词典,英文翻译,专业英语

热门文章

  1. 自动连击左键,F键和自动按住W键工具
  2. CSS进阶(7)- 样式补充
  3. 数据库学习记录806
  4. 字王·百字工程·2016中秋纪念
  5. 突出计算机学院的比赛名,学院在2019年全国大学生信息安全竞赛安徽省赛中喜获佳绩...
  6. JAVA高级特性(三)——Set集合
  7. matlab dae,matlab解DAE遇到的问题
  8. Ubuntu开机界面出现“error found when loading /root/.profile”(修改用户权限)
  9. 指定端口启动minio
  10. 基于MongoDB的学生成绩数据操作