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

Lottie Animation works only once #251

Closed
jesussmile opened this issue Dec 27, 2022 · 2 comments
Closed

Lottie Animation works only once #251

jesussmile opened this issue Dec 27, 2022 · 2 comments

Comments

@jesussmile
Copy link

jesussmile commented Dec 27, 2022

I am using Lottie Animation and want it to animate everytime I click on it , To this I am using GestureDetector However it only works the first time then for some reason it wont work again
What am I doing wrong here ?
Here is the code

import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';

void main() async {
  runApp(const App());
}

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() {
    return _AppState();
  }
}

class _AppState extends State<App> with SingleTickerProviderStateMixin {
  late final AnimationController my_location_controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    my_location_controller =
        AnimationController(vsync: this, duration: const Duration(seconds: 5));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      color: Colors.lightBlue,
      home: Scaffold(
        backgroundColor: Colors.lightBlue,
        body: Center(
          child: SizedBox(
            width: 300,
            height: 300,
            child: GestureDetector(
              onTap: () {
                my_location_controller.forward();
              },
              child: Lottie.asset(
                'assets/my_location.json',
                controller: my_location_controller,
                animate: true,
                repeat: true,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
@xvrh
Copy link
Owner

xvrh commented Jan 7, 2023

I think you need to call reset() on my_animation_controller before forward()

my_animation_controller..reset()..forward();

@jesussmile
Copy link
Author

Thnx

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