简体   繁体   English

Flutter:如何为特定的转换禁用英雄动画

[英]Flutter: How to disable Hero animations for a specific transition

Because I am reusing the same components in different contexts, unwanted Hero animations are displayed in the wrong transitions and my app is looking very glitchy.因为我在不同的上下文中重复使用相同的组件,所以不需要的 Hero 动画显示在错误的过渡中,而且我的应用程序看起来非常有问题。

This is happening in a rather vanilla project, using MaterialApp and pushNamed for navigation.这发生在一个相当普通的项目中,使用MaterialApppushNamed进行导航。

How can I enable or disable these animations in specific transitions?如何在特定的过渡中启用或禁用这些动画?

To programmatically disable the Hero animation the flutter has HeroMode Widget要以编程方式禁用 Hero animation flutter 具有 HeroMode 小部件

You have to wrap your Hero with a HeroMode and pass a bool value to the enabled: parameter你必须用 HeroMode 包装你的 Hero 并将 bool 值传递给enabled:参数

HeroMode(
  child: Hero(
  tag: "my-hero",
  ),
  enabled: false, // Your condition here
)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM