applyViewportDimension method

  1. @override
bool applyViewportDimension(
  1. double viewportDimension

Called when the viewport's extents are established.

The argument is the dimension of the RenderViewport in the main axis (e.g. the height, for a vertical viewport).

This may be called redundantly, with the same value, each frame. This is called during layout for the RenderViewport. If the viewport is configured to shrink-wrap its contents, it may be called several times, since the layout is repeated each time the scroll offset is corrected.

If this is called, it is called before applyContentDimensions. If this is called, applyContentDimensions will be called soon afterwards in the same layout phase. If the viewport is not configured to shrink-wrap its contents, then this will only be called when the viewport recomputes its size (i.e. when its parent lays out), and not during normal scrolling.

If applying the viewport dimensions changes the scroll offset, return false. Otherwise, return true. If you return false, the RenderViewport will be laid out again with the new scroll offset. This is expensive. (The return value is answering the question "did you accept these viewport dimensions unconditionally?"; if the new dimensions change the ViewportOffset's actual pixels value, then the viewport will need to be laid out again.)


bool applyViewportDimension(double viewportDimension) {
  if (_viewportDimension != viewportDimension) {
    _viewportDimension = viewportDimension;
    _didChangeViewportDimensionOrReceiveCorrection = true;
    // If this is called, you can rely on applyContentDimensions being called
    // soon afterwards in the same layout phase. So we put all the logic that
    // relies on both values being computed into applyContentDimensions.
  return true;