According to the docs, didUpdateWidget() is
Called whenever the widget configuration changes.
I took this to mean that didUpdateWidget() will be triggered if a widget is being rebuilt with an argument that is different than the argument it was given in the previous build. But after a simple test I seem to stand corrected:
Example :
class A extends StatefulWidget {
const A({Key key}) : super(key: key);
@override
State<A> createState() => _AState();
}
class _AState extends State<A> {
@override
Widget build(BuildContext context) {
return Center(
child: GestureDetector(
onTapDown: (_) => setState(() {}),
child: Container(
width: 300,
height: 300,
color: Colors.blue,
child: B(6),
),
),
);
}
}
class B extends StatefulWidget {
final int x;
const B(this.x, {Key key}) : super(key: key);
@override
_BState createState() => _BState();
}
class _BState extends State<B> {
@override
void didUpdateWidget(covariant B oldWidget) {
print('[${DateTime.now()}] widget has changed!');
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) => Container();
}
A has a child B that it rebuilds after every tap down gesture, and passes to it the int 6. Even though the argument remains the same, didUpdateWidget() gets invoked on every tap down.
On the other hand, if instead of 'B(6)' I give as an argument 'const B(6)', then didUpdateWidget() does not fire.
So am I to understand that an instance of a widget in and of itself is considered a configuration? Two instances of the same widget class with the exact same arguments are considered different configurations?