I want to play lottie animation for specific time duration in flutter. I don't want to play it by fast forwarding. Like If my animation contains total 90 frames
then If I only want to play first 30 frames
so can I achieve this? or like If my animation has total 2 seconds but I only want to play 1st second. then How can I do this with using animation controller or any other thing?
Asked
Active
Viewed 9,832 times
2

Aayush Shah
- 584
- 1
- 8
- 17
1 Answers
5
Okay you could try directly editing the controller instead, so you're initState will look like this:
@override
void initState() {
super.initState();
_controller = AnimationController(vsync: this);
_controller.addListener(() {
print(_controller.value);
// if the full duration of the animation is 8 secs then 0.5 is 4 secs
if (_controller.value > 0.5) {
// When it gets there hold it there.
_controller.value = 0.5;
}
});
}
and then your lottie widget looks like this:
Lottie.asset(
'asset/path.json',
controller: _controller,
onLoaded: (comp){
_controller
..duration = comp.duration
..forward();
})
----------- Previous answer below -----------
haven't had a chance to check this but try adding a controller to your animation and using animateTo on the onLoaded.
Lottie.asset(
'asset/path.json',
controller: _controller,
onLoaded: (comp){
_controller.animateTo(frameNumber);
})

Tyrell James
- 151
- 3
-
Thanks for the answer, but I had already tried this before but it is not working as I expected. Specifically, I have a animation which is of total of 90 frames but only first 30 frames are moving. the last 60 frames are steady which I don't want in my app because I am also reversing that animation after the animations gets completed. but as it has 60 frames steady, I get a lag of `1 second`. so I want to remove that lag of steady frames. Please share If you have any other alternative. Thanks in advance :) – Aayush Shah Jun 10 '21 at 07:00
-
You could try adding a listener to your controller and pausing it there. I'll post a new answer below. – Tyrell James Jun 10 '21 at 14:31