Answers for "flutter What is Tween Animation?"

0

Flutter Tween animation by flutter420

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FlutterAnimation(),
    );
  }
}

class FlutterAnimation extends StatefulWidget {
  @override
  _FlutterAnimationState createState() => _FlutterAnimationState();
}

class _FlutterAnimationState extends State<FlutterAnimation>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  Animation<Color> colorAnimation;
  Animation<double> sizeAnimation;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 2));
    colorAnimation =
        ColorTween(begin: Colors.black, end: Colors.green).animate(_controller);

    sizeAnimation = Tween<double>(begin: 100, end: 500).animate(_controller);

    _controller.addListener(() {
      setState(() {});
    });
    _controller.forward();
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: sizeAnimation.value,
          width: sizeAnimation.value,
          color: colorAnimation.value,
        ),
      ),
    );
  }
}
Posted by: Guest on May-24-2021
0

flutter What is Tween Animation?

It is the short form of in-betweening. In a tween animation, it is required to define the start and endpoint of animation. It means the animation begins with the start value, then goes through a series of intermediate values and finally reached the end value. It also provides the timeline and curve, which defines the time and speed of the transition. The widget framework provides a calculation of how to transition from the start and endpoint.
Posted by: Guest on October-27-2021

Browse Popular Code Answers by Language