我注意到当我扩展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())
我觉得最后一种解决方法特别奇怪。知道我缺少什么吗?该文档说,热重装将重建所有小部件。