我注意到当我扩展 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())
我发现最后的解决方法特别奇怪。知道我错过了什么吗?文档说热重载将重建所有小部件。