Hi everyone ,I have a problem, I don’t understand the difference between AnimatedWidget
and AnimatedBuilder
. The comments in the source code are as follows:
AnimatedWidget:
/// For more complex case involving additional state, consider using
/// [AnimatedBuilder].
AnimatedBuilder:
/// For simple cases without additional state, consider using
/// [AnimatedWidget].
I want to know how to choose between them, because I don't quite understand the documentation, thanks!
There's no real difference between them besides the syntax needed to use it.
To be clear, this is the code of AnimatedBuilder
:
class AnimatedBuilder extends AnimatedWidget {
const AnimatedBuilder({
Key key,
@required Listenable animation,
@required this.builder,
this.child,
}) : assert(builder != null),
super(key: key, listenable: animation);
final TransitionBuilder builder;
final Widget child;
@override
Widget build(BuildContext context) {
return builder(context, child);
}
}
...Yup, does nothing
From this code we can clearly see that AnimatedBuilder
is just a different syntax of using AnimatedWidget
. Since AnimatedBuilder
is an AnimatedWidget
that delegate all the layout logic to a callback
So in the end, it's really up to you. Both do the same thing. Use what makes it more readable for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With