I'm trying to put several animations for one widget, but as I'm beginner of Flutter, I don't know what feature I have to use to perform this. When there was only one animation per one widget, it was fine. Just add one bool to field and cover widget with AnimatedContainer. Like this,
bool init = false; //Bool about animation
//Somewhere of codes...
child: AnimatedContainer(
transform: init ? matrixA : matrixB,
child: FlatButton(
child: Text("Press Me"),
onPressed: () {
//Change init to true
setState(() {
init = true;
});
}
) //FlatButton
) //AnimatedContainer
I can perform icon animation using Flare, and also can perform lazy animation using Future.delayed() (Sorry, if this behavior is bad practice, advise me if I'm doing wrong). Problem is that there must be several animations for one widget, and there will be about 3 widgets like this. I once tried to put 2 animation for one widget first of all. In my app, I put flare icon animation. After this animation ends, I'm making button show up. When users tap this button, button will go up to specific position. Since button must be at below screen at first, I will need 3 Matrix4 variables. I tried to put 2 animation to one widget with same way above and this was the result.
bool init = false; //This will make button show up
bool pressed = false; //This will make button go up
//Somewhere of codes...
children: [
FlareActor("assets/animation.flr",
animation: "anim",
callback: (name) {
//Notify flare animation is ended
//and make button show up by calling setState
if(name == "anim") {
this.setState(() {
init = true;
});
}
}), //FlareActor
AnimatedContainer(
transform: init ? pressed ? matrixA : matrixB : matrixC, //This is problem
duration: pressed ? Duration(milliseconds: 300) : Duration(millisecons: 150),
child:FlatButton(
child: Text("Press Me"),
onPressed: () {
//Change pressed to true to make it move up
setState(() {
pressed = true;
});
}
) //FlatButton
) //AnimatedContainer
]
I know this codes don't contain full information (like matrixA, matrixB, matrixC), but I think this is enough to make you understand what I'm trying to do. If you need more information about codes, you can ask me at comment. I just put 2 bools into field and... it already started to look complicated, especially transform parameter in AnimatedContainer. Imagine that there will be 4 bools for each 3 widgets, there will be 12 bools in total, and this will make codes a lot messed up and look like complicated.
You may ask why I'm trying to put several animations to 1 widget, but well, just simply because I'm trying to make app more alive, not just simple screen change, dialog, or boring animation. Of course, I searched about this and what I found was Stream and AnimatedBuilder. I don't know if Stream can help me because even though I use Stream, I can't directly set property (location, scale, opacity) of widgets. Just sending boolean to listener, and calling setState(), and it becomes same like above. AnimatedBuilder looked fine, but all posts I found were about Putting animation to several widgets, not Putting several animation to one widget.
So here are the questions :
- Is this the only way to perform several animations to 1 widget?
- If no in first question, what will be better (or the best) way to perform this?