Flutter - AnimationController

class _WelcomeScreenState extends State<WelcomeScreen>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation animation;

@override
void initState() {
super.initState();

controller = AnimationController(
duration: Duration(seconds: 1), //0 to 1 in 60 steps tickers.
vsync: this,
//SingleTickerProviderStateMixin class is going to provide animation Ticker
// upperBound: 100.0,有curve class必須小於1,以避免衝突
);
animation = CurvedAnimation(
parent: controller, curve: Curves.easeIn); //upperBound 需小於1

controller.forward();
//Get the animation to start. proceed the animation forward(small to big)
controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {

controller.reverse(from: 1.0);//值由小到大
} else if (status == AnimationStatus.dismissed) {
controller.forward();
}
print(animation.status);
});

//Calls the listener every time the value of the animation changes.
controller.addListener(() {
setState(() {}); //call build()again and again.

print(controller.value);
});
}

@override
void dispose() {
//在頁面毀之前,釋放記憶體,別再暫用資料。
super.dispose();
controller.dispose();

} 

Comments

Popular posts from this blog

Go-VSCode -Autocomplete and Auto-import

Go - mail