title: Flutter : Difference in behavior by initializing with didChangeDependencies instead of initState
body: <p><a href="https://github.com/flutter/codelabs/blob/main/cookbook/lib/examples/ui_loading_animation.dart" rel="nofollow noreferrer">https://github.com/flutter/codelabs/blob/main/cookbook/lib/examples/ui_loading_animation.dart</a></p>
  <p>Question1 :</p>
  <p>In the _ShimmerLoadingState class in the above sample code, animation(Listenable) is set to _shimmerChanges in didChangeDependencies.</p>
  <p>When I deleted didChangeDependencies and defined the following initState and executed it, I got almost the same behavior.
  (Looks the same to me).</p>
  <pre><code>  @override
    void initState(){
      super.initState();
      _shimmerChanges = Shimmer.of(context)?.shimmerChanges;
      _shimmerChanges!.addListener(_onShimmerChange);
    }
  </code></pre>
  <p>I guess it depends on what kind of implementation and behavior you want in the end, but in this sample code, does using didChangeDependencies instead of initState make any difference?</p>
  <p>Even if there is no difference here, is there any possible reason to use didChangeDependencies in a real-world use case?</p>
  <hr />
  <p>Question2 :
  In this sample code, the following location in didChangeDependencies is not executed. I am not sure why this part is necessary.
  What is this code supposed to do?</p>
  <pre><code>    if (_shimmerChanges != null) {
        _shimmerChanges!.removeListener(_onShimmerChange);
      }
  </code></pre>