简体   繁体   English

如何使用 auto_route package 在 flutter 应用程序中重新启动 TabPage 上的构建方法

[英]How to restart the build method on TabPage in flutter app with auto_route package

Hi a use auto_route package in flutter app.您好,请在 flutter 应用程序中使用 auto_route package。 How to restart the build method on TabPage or not save the stack state when switching tabs. state 切换标签页时如何在TabPage上重启build方法或不保存堆栈。 I should have an animation run in the build method on TabPage every time I switch a tab in the navigation bar.每次在导航栏中切换选项卡时,我都应该在 TabPage 的构建方法中运行 animation。 But the build method is not called when I click the buttons in the navigation bar但是当我单击导航栏中的按钮时不会调用构建方法

I guess you are the same user that commented on my article.我猜你就是评论我文章的那个用户。 I'll give the same answer here.我会在这里给出相同的答案。 this is not related to the autoroute package itself but it is the default behavior of a bottombar navigation.这与自动路由 package 本身无关,但它是底部导航栏的默认行为。 The objective being to always minimize the number of rebuilds necessary for your UI.目标是始终尽量减少 UI 所需的重建次数。

I didn't test it but you could try to make your tab a stateful widget (if it isn't already) and modify this behavior with the AutomaticKeepAliveClientMixin<YourWidget> :我没有测试它,但您可以尝试使您的选项卡成为有状态的小部件(如果它还没有)并使用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; 

 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将flutter升级到1.22.0后auto_route包的问题 - problem with auto_route package after upgrading flutter to 1.22.0 使用 Flutter 中的 auto_route package 到同一页面的多个路径 - Having multiple paths to the same page with the auto_route package in Flutter Flutter 自动路线 | 如何使用 BlocProvider 包装路由? - Flutter auto_route | How do I wrap a route with BlocProvider? flutter web auto_route:维护模式 - flutter web auto_route: Maintenance Mode Flutter - auto_route _CustomNavigatorState 错误 - Flutter - auto_route _CustomNavigatorState error Flutter:尝试将 BlocProvider 与 get_it 和 auto_route package 结合使用,但上下文找不到提供程序 - Flutter: Try to use BlocProvider with get_it and auto_route package but context don't find provider 在 Flutter auto_route package 中,我需要将构建器转换为什么类型? - In Flutter auto_route package, what type do I need to cast the builder as? 当用户输入 URL 地址时,如何在 flutter 中传入 arguments(使用 auto_route) - How to pass in arguments in flutter when user input URL address (using auto_route) 在 flutter 中使用 auto_route 时如何将数据传递到屏幕? - How do I pass data to a screen while using auto_route in flutter? 如何使用带有 auto_route 的嵌套路由在 Flutter 中的屏幕之间导航 - How to navigate between screens in Flutter using nested routing with auto_route
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM