Petro
Petro

Reputation: 3652

Flutter Animation Controller The argument type 'ExampleWidget' or 'this' can't be assigned to the parameter type 'TickerProvider'

I'm following this guide for an animation: https://mightytechno.com/flutter-glow-pulse-animation/

When I go to use this it won't let me pass it. I can't compile and flutter clean does nothing. What object can I pass to get rid of this error?

enter image description here

void initState() {    
    getSharedPrefs();
    _animationController = AnimationController(vsync: this, duration: Duration(seconds: 2));
    _animationController.repeat(reverse: true);
    _animation =  Tween(begin: 2.0,end: 15.0).animate(_animationController)..addListener((){
      setState(() {

      });
    });

Upvotes: 2

Views: 1644

Answers (2)

er.arunkushwaha
er.arunkushwaha

Reputation: 156

You need to use the SingleTickerProviderStateMixin to use this as vsync param. You can achieve this by using with keyword here is how:

class Social4state extends State<UserProfilePage> with SingleTickerProviderStateMixin

Upvotes: 0

Petro
Petro

Reputation: 3652

Extending SingleTickerProviderStateMixin fixed the issue:

class Social4state extends State<UserProfilePage> with SingleTickerProviderStateMixin{

Upvotes: 6

Related Questions