How does the tag property on a Hero widget genuinely and uniquely identify exactly which specific widget on one screen properly corresponds to a genuinely matching widget on an entirely different destination screen?
Short answer
The tag property serves as a genuinely unique identifier that Flutter actually uses to correctly match a specific Hero widget on your originating screen to its own genuinely corresponding matching Hero widget on the destination screen, and this tag value can genuinely be any…
Advertisement
AModel answer
The tag property serves as a genuinely unique identifier that Flutter actually uses to correctly match a specific Hero widget on your originating screen to its own genuinely corresponding matching Hero widget on the destination screen, and this tag value can genuinely be any object at all, though it is most commonly a specific string or a genuinely unique identifier directly and uniquely tied to the actual specific piece of content being displayed, such as that particular specific product's own unique database identifier, ensuring the genuinely correct exact matching pair of widgets are properly connected together for that specific particular flight animation.
Hero(tag: product.id, child: ProductImage(product: product))Real-world example
A recipe app uses each specific recipe's own genuinely unique database identifier as its Hero tag, correctly ensuring the exact right specific recipe photo smoothly transitions between the main recipe list screen and that exact same specific recipe's own individual detail screen every single time.
Likely follow-ups
- What genuinely happens if you accidentally forget to include a Hero widget on one of the two involved screens?
- Can a genuinely simple plain string literal safely be used as a Hero tag if there is truly only ever going to be one single Hero widget genuinely present on a given screen?
Related topics