notifyViewportSizeChangedFromLayout method
void
notifyViewportSizeChangedFromLayout()
Implementation
void notifyViewportSizeChangedFromLayout() {
if (!_inited || _disposed) return;
// This method can be invoked from RenderViewportBox.performLayout(). We
// must not mutate descendants (e.g. markNeedsLayout) during layout, so
// defer all side effects to a post-frame callback.
if (_viewportSizeChangePostFrameCallbackScheduled) return;
_viewportSizeChangePostFrameCallbackScheduled = true;
SchedulerBinding.instance.addPostFrameCallback((_) {
_viewportSizeChangePostFrameCallbackScheduled = false;
if (!_inited || _disposed) return;
if (enableBlink) {
// Viewport size changes driven by widget constraints do not necessarily
// trigger WidgetsBindingObserver.didChangeMetrics(). Avoid the debounce
// timer here so the native viewport cache stays in sync promptly.
_nativeMediaQueryAffectingValueDebounceTimer?.cancel();
_nativeMediaQueryAffectingValueDebounceTimer = null;
_flushNativeMediaQueryAffectingValueChanged();
}
// Mark viewport-size-relative properties dirty so vw/vh/etc can
// recompute against the new viewport size.
window.resizeViewportRelatedElements();
// Recalculate styles so media queries (including @layer ordering inside
// conditional groups) re-evaluate against the new viewport size.
if (!enableBlink) {
document.recalculateStyleImmediately();
}
});
SchedulerBinding.instance.scheduleFrame();
}