Using AnimatedBuilder
Looking at the code that we wrote in the previous section, we can see a small problem with it – our button animation is mixed up with other widgets. So long as our code does not scale and become more complex, this is fine, but we know this is not the case most of the time, so we might have a real problem.
The AnimatedBuilder
class can help us with the task of separating responsibilities. Our widget, whether it is ElevatedButton
or anything else, does not need to know it is rendered in animation, and breaking down the build
method to widgets that each have a single responsibility can be seen as one of the fundamental concepts in the Flutter framework. Let’s look at the AnimatedBuilder
class and then revisit our animation with our new knowledge.
The AnimatedBuilder class
The AnimatedBuilder
widget exists so that we can build complex widgets that wish to include animation as part of a larger build function. Just as with any other widget, it...