Listenable Parameter Animation of AnimateBuilder not accepting AnimationController

Issue

Flutter Beginner here. I am using Tween with an AnimationController. And I’m trying to use animate() method.

Error Says as follows

The argument type ‘AnimationController?’ can’t be assigned to the parameter type ‘Listenable’

Code I have used

Animation<double>? containerSize;
AnimationController? animationController;
Duration animationDuration = Duration(microseconds: 270);

initState method:

    void initState(){
       super.initState();
       SystemChrome.setEnabledSystemUIOverlays([]);
       animationController = AnimationController(vsync: this, duration: animationDuration);
   }

Tween Method declared Inside the Widget:

containerSize = Tween<double>(begin: size.height * 0.1, end: defaultRegisterSize).animate(CurvedAnimation(parent: animationController!, curve: Curves.linear));

AnimateBuiler inside the Scaffold->Body->stack->children

//Register container
          AnimatedBuilder(
            animation: animationController,
            builder: (context, child){
              return buildRegisterContainer();
            },
          )

Calling at the Inkwell->GestureDetector

GestureDetector(
          onTap: (){
            animationController?.forward();

            setState(() {
              isLogin = !isLogin;  
            });
          }

How to assign AnimationController to the animation parameter of AnimateBuilder?

Solution

Add ! to make it non-null like so:

  AnimatedBuilder(
    animation: animationController!,
    builder: (context, child){
       return buildRegisterContainer();
    },
  )

Answered By – Josteve

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.