Flutter Hero in FutureBuilder

536 Views Asked by At

I am scratching my head to find an easy way to make a hero animation work when the target hero is in a FutureBuilder. I know this is not working because the hero image has to be be present on the very first frame of the second screen, which obviously cannot be the case when getting the data from Firestore through a FutureBuilder.

Here is my code:

First screen:

 Hero(
    tag: "postImage",
    child: Image.network(post.imageurl),
  ),

Second Screen:

FutureBuilder(
      future: _futurePost,
      builder: (context, AsyncSnapshot snapshot) {
      [...]
      return  Hero(
        tag: "postImage",
        child: Image.network(snapshot.data.imageurl),
      );
    }
  )

How to achieve this? I am pretty surprised this is not a common question!

Thank you!

0

There are 0 best solutions below