import 'package:flutter/material.
dart';
void main() {
runApp(MyApp());}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Animation Examples',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: AnimationExamples(),
);
}
}
class AnimationExamples extends StatefulWidget {
@override
_AnimationExamplesState createState() => _AnimationExamplesState();
}
class _AnimationExamplesState extends State<AnimationExamples> with
SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _fadeAnimation;
late Animation<Offset> _slideAnimation;
late
Animation<double>
_scaleAnimation; @override void initState() {
super.initState();
_controller = AnimationController(
duration: Duration(seconds: 2),
vsync: this,
)..repeat(reverse: true);
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(_controller);
_slideAnimation = Tween<Offset>(begin: Offset(1.0, 0.0), end:
Offset.zero).animate(_controller);
_scaleAnimation = Tween<double>(begin: 0.5, end: 1.0).animate(_controller);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Animation Examples')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FadeTransition(
opacity: _fadeAnimation,
child: Container(
width: 100,
height: 100,
color: Colors.blue,
), ),
SizedBox(height: 20),
SlideTransition(
position: _slideAnimation,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
SizedBox(height: 20),
ScaleTransition(
scale: _scaleAnimation,
child: Container(
width: 100,
height: 100,
color: Colors.green,),),],),),);}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}