大家好,在flutter应用程序中使用auto_route包。如何在切换选项卡时重新启动TabPage上的build方法或不保存堆栈状态。我应该在每次切换导航栏中的选项卡时,在TabPage上的build方法中运行一个动画。但是当我单击导航栏中的按钮时,不会调用build方法
发布于 2021-10-08 18:52:47
我猜你就是那个评论我的文章的用户。我会在这里给出同样的答案。这与autoroute包本身无关,但它是bottombar导航的默认行为。目标是始终最小化UI所需的重建次数。
我没有对其进行测试,但是您可以尝试将选项卡设置为有状态小部件(如果还没有这样做的话),并使用AutomaticKeepAliveClientMixin<YourWidget>修改此行为
class _YourWidgetState extends State<YourWidget> with AutomaticKeepAliveClientMixin<YourWidget>{
// Here you build your Widget after calling the super method
@override Widget build(BuildContext context) {
super.build(context)
return Container();
}
// the important part is returning false here
@override bool get wantKeepAlive => false;
}https://stackoverflow.com/questions/69454512
复制相似问题