Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating multiple PhotoViewInline widgets in the same widget tree makes the app crash #26

Closed
zeyadkhaled opened this issue Aug 27, 2018 · 1 comment

Comments

@zeyadkhaled
Copy link
Contributor

So I am using the PhotoViewInline widget wrapped in a Card widget and displaying multiple Cards in a ListView.

So it worked fine until I tried to navigate to another context and Flutter started throwing this error:

There are multiple heroes that share the same tag within a subtree. Within each subtree for which heroes are to be animated (typically a PageRoute subtree), each Hero must have a unique non-null tag. In this case, multiple heroes had the following tag: nohero Here is the subtree for one of the offending heroes: # Hero(tag: nohero, state: _HeroState#db290)

I traced the Widget Tree until I found that PhotoViewInline didn't have a unique heroTag
, and thus when it calls its build method which has a PhotoView it will have a "nohero" heroTag.

I was able to fix this by adding a heroTag Object in the constructor of PhotoViewInline and passing that in the build method to the PhotoView heroTag like so:

class PhotoViewInline extends StatefulWidget{
  final ImageProvider imageProvider;
  final Widget loadingChild;
  final Color backgroundColor;
  final dynamic minScale;
  final dynamic maxScale;
  final Object heroTag;   //ADDED THIS

  const PhotoViewInline({
    Key key,
    @required this.imageProvider,
    this.loadingChild,
    this.backgroundColor = const Color.fromRGBO(0, 0, 0, 1.0),
    this.minScale,
    this.maxScale,
    this.heroTag, //ADDED THIS
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() => new _PhotoViewInlineState();
}

class _PhotoViewInlineState extends State<PhotoViewInline> with AfterLayoutMixin<PhotoViewInline>{

  Size _size;

  @override
  void afterFirstLayout(BuildContext context) {
    setState(() {
      _size = context.size;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new PhotoView(
      heroTag: widget.heroTag,  //ADDED THIS
      imageProvider: widget.imageProvider,
      loadingChild: widget.loadingChild,
      backgroundColor: widget.backgroundColor,
      minScale: widget.minScale,
      maxScale: widget.maxScale,
      size: _size,
    );
  }

Should I create a Pull Request with the fix?

@renancaraujo
Copy link
Member

I was sure that I had already done this at the 0.0.6 release. I must have forgotten.
Thanks for your PR #27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants