"type 'double' is not a subtype of type 'int' in type cast" error in flutter. What should i do?

2,643

All you need is to explicitly state the type of your Tween to be double:

AnimationController(duration: Duration(seconds: 3), vsync: this);  
animation = Tween<double>(begin: -1, end: 0).animate(CurvedAnimation(curve: Curves.fastOutSlowIn, parent: animationController));
Share:
2,643
Admin
Author by

Admin

Updated on December 22, 2022

Comments

  • Admin
    Admin 11 months

    enter image description here

    I am doing a simple Curves Animation in flutter, but i am always getting an error like this "type 'double' is not a subtype of type 'int' in type cast" , what error i have made here?

    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    class _HomePageState extends State<HomePage>
        with SingleTickerProviderStateMixin {
      Animation animation;
      AnimationController animationController;
      @override
      void initState() {
        super.initState();
        animationController =
            AnimationController(duration: Duration(seconds: 3), vsync: this);
        animation = Tween(begin: -1, end: 0).animate(CurvedAnimation(
            curve: Curves.fastOutSlowIn, parent: animationController));
      }
      @override
      Widget build(BuildContext context) {
        final double width = MediaQuery.of(context).size.width;
        animationController.forward();
        return AnimatedBuilder(
            animation: animationController,
            builder: (BuildContext context, Widget child) {
              return Scaffold(
                body: Transform(
                  transform:
                      Matrix4.translationValues(animation.value * width, 0, 0),
                  child: Center(
                    child: Text(
                      "Welcome",
                      style: TextStyle(fontWeight: FontWeight.bold, fontSize: 50),
                    ),
                  ),
                ),
              );
            });
      }
    }