Flutter:热重载和路由

时间:2018-10-31 12:50:58

标签: routes dart flutter hot-reload

我注意到当我扩展MaterialPageRoutes然后像这样实例化它们

class Route extends MaterialPageRoute {
  Route(): super(
    builder: (context) {
      return SomeWidget();
    }
  );
}
...somewhere in the build method of another class...
Navigator.push(context, Route())

热重载不会像我一样重建路由的内容

...somewhere in the build method of another class...
Navigator.push(context, MaterialPageRoute(
  builder: (context) {
    return SomeWidget();
  }
))

class Route extends MaterialPageRoute {
  Route(): super(
    builder: (context) {
      return RouteWidget();
    }
  );
}
class RouteWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return SomeWidget();
  }
}
...somewhere in the build method of another class...
Navigator.push(context, Route())

我觉得最后一种解决方法特别奇怪。知道我缺少什么吗?该文档说,热重装将重建所有小部件。

0 个答案:

没有答案