Flutter: How to disable Hero animations for a specific transition

Viewed 397

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.

This is happening in a rather vanilla project, using MaterialApp and pushNamed for navigation.

How can I enable or disable these animations in specific transitions?

1 Answers

To programmatically disable the Hero animation the flutter has HeroMode Widget

You have to wrap your Hero with a HeroMode and pass a bool value to the enabled: parameter

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