import
'package:flutter/material.dart'
;
import
'package:simple_animations/simple_animations.dart'
;
void
main() => runApp(MyApp());
class
MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green,
),
debugShowCheckedModeBanner:
false
,
home: Scaffold(
appBar: AppBar(
title: Text(
'Movie Tween'
),
),
body: Center(
child: MovieTweenAnim(),
),
),
);
}
}
class
MovieTweenAnim extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MovieTween tween = MovieTween()
..scene(
begin:
const
Duration(milliseconds: 0),
end:
const
Duration(milliseconds: 1000))
.tween(
'width'
, Tween(begin: 0.0, end: 100.0))
..scene(
begin:
const
Duration(milliseconds: 1000),
end:
const
Duration(milliseconds: 1800))
.tween(
'width'
, Tween(begin: 100.0, end: 200.0))
..scene(
begin:
const
Duration(milliseconds: 0),
duration:
const
Duration(milliseconds: 2500))
.tween(
'height'
, Tween(begin: 0.0, end: 200.0))
..scene(
begin:
const
Duration(milliseconds: 0),
duration:
const
Duration(milliseconds: 3000))
.tween(
'color'
, ColorTween(begin: Colors.orange, end: Colors.green));
return
Scaffold(
backgroundColor: Colors.white,
body: Center(
child: _DelayedAnimation(tween: tween),
),
);
}
}
class
_DelayedAnimation extends StatefulWidget {
final MovieTween tween;
const
_DelayedAnimation({Key? key, required
this
.tween}) : super(key: key);
@override
_DelayedAnimationState createState() => _DelayedAnimationState();
}
class
_DelayedAnimationState extends State<_DelayedAnimation> {
bool
isAnimating =
false
;
@override
void
initState() {
super.initState();
Future.delayed(Duration(seconds: 5), () {
setState(() {
isAnimating =
true
;
});
});
}
@override
Widget build(BuildContext context) {
return
PlayAnimationBuilder<Movie>(
tween: widget.tween,
duration: widget.tween.duration,
delay: isAnimating ? Duration() : Duration(seconds: 5),
builder: (context, value, child) {
return
Container(
width: value.get(
'width'
),
height: value.get(
'height'
),
color: value.get(
'color'
),
);
},
);
}
}