didChangeDependencies method

  1. @override
void didChangeDependencies()
override

Called when a dependency of this element changes.

The dependOnInheritedWidgetOfExactType registers this element as depending on inherited information of the given type. When the information of that type changes at this location in the tree (e.g., because the InheritedElement updated to a new InheritedWidget and InheritedWidget.updateShouldNotify returned true), the framework calls this function to notify this element of the change.

Implementation

@override
void didChangeDependencies() {
  super.didChangeDependencies();
  // Fourth [_dirtyKeys] producer. Rows build with THIS element as their
  // BuildContext (see [createChild]), so every inherited read a
  // nodeBuilder performs registers here; a Theme / MediaQuery /
  // DefaultTextStyle change means every mounted row's builder output
  // may differ. Same lazy shape as [update]: queue, mark layout, let
  // [createChild] rebuild the cache-region and sticky rows the next
  // layout reaches (see [_dirtyKeys]). NOT only the cache region:
  // sticky headers the cache region rejected are force-created too
  // (the sticky block's force-create measurement in
  // `RenderSliverTree.performLayout`).
  if (_children.isEmpty) {
    return;
  }
  _dirtyKeys.addAll(_children.keys);
  renderObject.markNeedsLayout();
}