I'm trying to better understand what is happening in the
official example
for AnimatedPositioned
.
From this
article
(and accompanying video)
we know that even if the widget object itself remains the same, but just changes position
in the widget tree, then we have to include a key if the widget is a StatefulWidget
.
Well, in the
official example
for AnimatedPositioned
, there is no key used.
When selected
is flipped, setState
triggers a second call for the build()
method.
Not only does this second call not just reposition the exact same StatelessWidget
,
it also creates an entirely new AnimatedPositioned
object.
How does Flutter know that this widget is the same widget as before (to animate it properly)? Is it just the position in the widget tree? But we could have multiple widgets, and this is a StatefulWidget
.
Why is a key sometimes not needed for a StatefulWidget?