flutter_swiper icon indicating copy to clipboard operation
flutter_swiper copied to clipboard

There are multiple heroes that share the same tag within a subtree.

Open fernando-s97 opened this issue 5 years ago • 1 comments

Hi!

My Swiper list (EventsList) has 2 items, but 3 items appear in the widget tree. image And as I'm using the Hero widget, I'm getting the following error image How can I solve that?

In this case, the 1st and 3rd items are the same.

fernando-s97 avatar Oct 11 '20 01:10 fernando-s97

I was having the same problem. This seems to be the occurring because the Swiper widget build the first item twice, at the top and the bottom of the stack. This can be seen here (the first item, 1, is built two times ):

image

This means that any widget at the top of the stack will have a duplicate widget thus all the property passed to that widget are also duplicated. (No matter how unique the data id)

What worked for me:

Defining a global id (say 'heroId') and incrementing it on every build:

image

We use this, 'heroId' as the hero tag by passing it on new when navigating to the target screen via the constructor:

image

Hope this helped you!

realshovanshah avatar May 10 '21 21:05 realshovanshah