Flutter Animation : TweenAnimationBuilder

mobile academy


import 'package:flutter/material.dart';

class TweenAnimation extends StatefulWidget {
  const TweenAnimation({Key? key}) : super(key: key);

  @override
  State<TweenAnimation> createState() => _TweenAnimationState();
}

class _TweenAnimationState extends State<TweenAnimation> {
  double _size = 100;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Column(
          children: [
            const SizedBox(height: 50,),
            
            TweenAnimationBuilder(
              tween: Tween(begin: 0.0, end: _size), 
              duration: const Duration(milliseconds: 2000), 
              builder: (context, value, child) {
                return Image.asset(
                  'assets/user1.jpg',
                  width: value,
                  height: value,
                );                
              },
              curve: Curves.bounceIn,
              onEnd: () {
                setState(() {
                  _size = _size == 100 ? 300 : 100;                  
                });
                
              },
            ),
            const SizedBox(height: 8,),

          ],
        ),
      ),
    );
  }
}
Select your currency
USD United States (US) dollar