1. When is didUpdateWidget() called and what is its purpose?
DidUpdateWidget() is called when the parent rebuilds and provides a new widget instance with different parameters. It receives the old widget as a parameter, allowing you to compare old and new configurations and react to changes. This is your opportunity to update state or reinitialize resources based on new widget properties. For example, if a parent passes different data to your StatefulWidget, didUpdateWidget() is called with the old widget, and you can compare oldWidget.data with widget.data to detect changes. If they differ, you can update your state or reinitialize resources accordingly. This is followed by a call to build(). Common uses include restarting animations when animation parameters change, reinitializing controllers when configuration changes, or updating subscriptions when parameters change. Always call super.didUpdateWidget(oldWidget) to ensure proper parent class handling. DidUpdateWidget() is called before build() whenever the widget is updated, giving you a chance to synchronize state with new configuration.