Skip to content

Document that Hero needs everything present and ready on frame zero of the transition animation #15586

Closed

Description

@smkhalsa

Steps to Reproduce

When navigating from a list view which displays the below CollectionPhoto to the CollectionDetails screen, the Hero animation is not shown. However, when I press the back button from the CollectionDetails page, the animation shows the image moving back into the list.

class CollectionPhoto extends StatelessWidget {
  CollectionPhoto({ Key key, this.imageName, this.collectionId,  }) : super(key: key);

  final String imageName;
  final String collectionId;

  @override
  Widget build(BuildContext context) {
    return new Material(
      color: Colors.transparent,
      child: new InkWell(
        onTap: () {
          Application.router.navigateTo(context, '/collections/$collectionId', transition: TransitionType.native);
        },
        child: new Hero(
          tag: '$collectionId-image',
          child: new Image.network(URLS.getCollectionImageURL(imageName)),
        )
      )
    );
  }
}
class CollectionDetails extends StatelessWidget {
  CollectionDetails({ Key key, this.id }) : super(key: key);
  
  final String id;

  @override
  Widget build(BuildContext context) {
    return new StreamBuilder(
      stream: Firestore.instance.collection('collections')
        .document(id)
        .snapshots,
      builder: (context, snapshot) {
        if (!snapshot.hasData) return new Text('Loading...');
        return new Scaffold(
          appBar: new AppBar(
            title: new Text(snapshot.data.data['name']),
          ),
          body: new Hero(
            tag: '$id-image',
            child: new Image.network(URLS.getCollectionImageURL(snapshot.data.data['imageName'])),
          )
        );
      },
    );
  }
}

Activity

  1. Hixie commented on Jun 12, 2018

    @Hixie
    Contributor

    For a Hero animation to trigger, the Hero has to exist on the very first frame of the new page's animation. In this case, since you are using a StreamBuilder, the first frame will only show "Loading...", and therefore there's no hero to animate.

    We should definitely make the documentation better.

  2. changed the title [-]Hero not animating with Network Image[/-] [+]Document that Hero needs everything present and ready on frame zero of the transition animation[/+] on Jun 12, 2018
  3. added this to the milestone on Jun 12, 2018
  4. apaatsio commented on Sep 26, 2018

    @apaatsio
    Contributor

    Is there a good workaround for this limitation? I have a similar situation with the exception that my stream data is from a local source (I'm using the BLoC pattern to manage state) so there is no network delay and thus basically no need for any kind of loading screen.

    A simplified version of the destination widget:

    class SecondScreen extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return StreamBuilder(
            stream: Stream.fromIterable([0]),
            builder: (context, snapshot) {
              return snapshot.hasData ? Hero(...) : Container();
            });
      }
    }

    Edit: I found a solution for my specific problem. Just have a synchronous getter for the data in the bloc and pass that as initialData for the StreamBuilder like described here: https://medium.com/@artemsidorenko/bloc-architecture-in-flutter-a-modern-architectural-approach-and-how-we-use-it-at-jimdo-bea143b56d01

  5. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    on Dec 10, 2018
  6. github-actions commented on Aug 15, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

d: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions