didUpdateBuildContext method
Intercepts element tree lifecycle changes when the bound BuildContext transitions.
This hook triggers ONLY when the underlying element instance changes (e.g., initial coupling, widget subtree reparenting, or decoupling).
oldContext: The previously bound BuildContext, ornullif unmounted or uncoupled.newContext: The newly bound active BuildContext, ornullif decoupled.
Design Philosophy: Provides an extension point for Computations that require imperative lifecycle notifications when moving across different positions in Flutter's element tree.
Ensures:
- Invoked only when
!identical(oldContext, newContext)at the element reference level.
AI & Developer Note:
- No Direct Framework Rebuilds: Calling
newContext?.dependOnInheritedWidgetOfExactType<T>()inside this hook will NOT automatically trigger an immediate widget rebuild. CoralWidgetElement delegates computation to Coralline's lazy topological pipeline and schedules a rebuild only when the reactive pipeline computes an updated UI subtree. - Automatic Dependency Cleanup: When the bound context or pipeline transitions,
tracked
InheritedElementdependencies are automatically flushed (_flushDependencies) to prevent ghost notifications and memory leaks. - Do Not Cache Context: Never store
newContextin local mutable fields. Doing so introduces stale element references and memory leaks. - Reactivity Best Practice: For UI dependencies (e.g., Theme, MediaQuery, InheritedWidgets),
use reactive context helpers (
context.theme,dependOn<T>(),coralOf<T>()) inside your Computation ormanifest()rather than imperatively subscribing in this hook.
Example:
@override
void didUpdateBuildContext(BuildContext? oldContext, BuildContext? newContext) {
super.didUpdateBuildContext(oldContext, newContext);
// Perform setup or cleanup on element binding transition
}
Implementation
void didUpdateBuildContext(
BuildContext? oldContext, BuildContext? newContext) {}