Animating a photo across screens in Flutter

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

We already made a photo grid to photo detail app in Flutter, and today we are building further on that application.
We'll be adding an animation so that the photo will expand to the new screen. Hero widgets are a very cool feature that Flutter gives us out of the box!
The Flutter hero animation looks like the example you see below:

Feel free to follow along and take this branch as the starting point.
The animation can be done through a Hero widget. This is a widget that takes content and a tag. This tag is what defines the animation between the two screens.
So sketch this out for you:
Flutter can then identify these two tags for you and animate between them.

The first thing we need to do is add the hero wrapper on the ScreenOne grid images.
Before this was the container widget, so we wrapped that in a hero widget and add a unique tag for this image (The actual image name).
child: Hero(
tag: _items[index].image,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(_items[index].image),
),
),
),
),
We also need to wrap the image in a receiving hero widget on the second screen widget.
child: Hero(
tag: image,
child: Image(
image: NetworkImage(image),
),
),
And now Flutter can identify these two images and will do all the animation for us, which is fantastic!
And that's how easy Hero animations in Flutter are. If you want to see the complete code example, check it out on GitHub.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter