通过 runApp() 进行 Flutter 状态和屏幕管理
Flutter state and Screen management via runApp()
我使用 runApp()
更改我的 flutter 应用程序中的所有屏幕,但我觉得这是一种不好的做法,因为我从未见过有人这样做(我只是认为这是一种简单快捷的更改方式屏幕或从另一个 class 中的小部件刷新当前屏幕,而不使用 setState()
功能的键)。我从来没有注意到这样做有任何性能缺陷,而且效果很好。
是否有理由使用 Navigator 等不同的东西?
的确,我从未见过有人这样做。但是,如果您阅读 runApp description 他们会说:
Calling runApp again will detach the previous root widget from the screen and attach the given widget in its place. The new widget tree is compared against the previous widget tree and any differences are applied to the underlying render tree, similar to what happens when a StatefulWidget rebuilds after calling State.setState.
因为它是预期用途,并且有树比较,我认为它是有效的。
Navigator 的优势在于您可以使用命名路由、在屏幕之间设置动画、拥有堆栈。如果你不需要那个,runApp 是完美的。
我使用 runApp()
更改我的 flutter 应用程序中的所有屏幕,但我觉得这是一种不好的做法,因为我从未见过有人这样做(我只是认为这是一种简单快捷的更改方式屏幕或从另一个 class 中的小部件刷新当前屏幕,而不使用 setState()
功能的键)。我从来没有注意到这样做有任何性能缺陷,而且效果很好。
是否有理由使用 Navigator 等不同的东西?
的确,我从未见过有人这样做。但是,如果您阅读 runApp description 他们会说:
Calling runApp again will detach the previous root widget from the screen and attach the given widget in its place. The new widget tree is compared against the previous widget tree and any differences are applied to the underlying render tree, similar to what happens when a StatefulWidget rebuilds after calling State.setState.
因为它是预期用途,并且有树比较,我认为它是有效的。
Navigator 的优势在于您可以使用命名路由、在屏幕之间设置动画、拥有堆栈。如果你不需要那个,runApp 是完美的。