I am building List (ListView.builder) and Detail Screen. Hero is used to animate some part when widget is selected (using pushedReplacement).
I noticed that when I move from Detail Screen to List screen, if the selected widget is the end/tail/last widget of the ListView, then the animation won't run.
Because ListView.builder is only rendering the first/head viewable element, I think Hero does not know the location of the widget.
So, how do I solve this problem? It's not that critical, but it's bugging me for days.
Add a Hero widget to the second screen To complete the connection with the first screen, wrap the Image on the second screen with a Hero widget that has the same tag as the Hero in the first screen. After applying the Hero widget to the second screen, the animation between screens just works.
Work flow of the Flutter AnimationAnimationController(duration: const Duration(seconds: 2), vsync: this); animation = Tween<double>(begin: 0, end: 300). animate(controller); controller. forward(); Add animation based listener, addListener to change the state of the widget.
Hero widget identifies the elements to animate by its tag. The tag property must be unique in order to make this work. So what you can do is:
Make the tag of each Hero unique. like,
ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext context, int index) {
return Hero(
tag: "some_name"+index.toString(),
child: SomeChild();
);
}
)
Pass the index to detailed screen on click. like,
Navigator.push(context,
MaterialPageRoute(
builder: (BuildContext context) => DetailedScreen(index)
)
);
on the detailed screen create the tag using the index received. like,
tag: "some_name"+index.toString()
Hope it will help you.
what u need is to provide unique tag to each list-builder element
Hero(
tag: snapshot.data.documents[index]['category'],
child: // your child ,
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With