Flutter › Hero Animations & Page Transitions
How can you properly customize a Hero animation's own specific flight path and behavior using a custom flightShuttleBuilder, rather than simply relying entirely on Flutter's own default built in animation behavior?
IntermediateAnswer
The flightShuttleBuilder property lets you provide your own genuinely fully custom widget to actually be displayed throughout the entire duration of a Hero animation's own particular flight, giving you genuinely full and complete creative control over exactly how that specific transitioning widget should actually visually look and precisely behave while it is actively still mid flight between the two screens, which is particularly useful whenever the originating and destination widgets genuinely differ meaningfully in their own specific visual appearance, such as one being displayed considerably smaller as a simple thumbnail and the other being displayed considerably larger as a genuinely full detailed view.
Hero(
tag: 'product-123',
flightShuttleBuilder: (context, animation, direction, fromContext, toContext) {
return Material(color: Colors.transparent, child: toContext.widget);
},
child: productImage,
)Real-world example A photo gallery app uses a custom flightShuttleBuilder to properly ensure a specific transitioning image consistently maintains a fully correct aspect ratio throughout its entire flight animation, even though the originating thumbnail and the considerably larger destination full screen image genuinely have somewhat meaningfully different actual specific dimensions.