performLayout method

  1. @override
void performLayout()

Do the work of computing the layout for this render object.

Do not call this function directly: call layout instead. This function is called by layout when there is actually work to be done by this render object during layout. The layout constraints provided by your parent are available via the constraints getter.

If sizedByParent is true, then this function should not actually change the dimensions of this render object. Instead, that work should be done by performResize. If sizedByParent is false, then this function should both change the dimensions of this render object and instruct its children to layout.

In implementing this function, you must call layout on each of your children, passing true for parentUsesSize if your layout information is dependent on your child's layout information. Passing true for parentUsesSize ensures that this render object will undergo layout if the child undergoes layout. Otherwise, the child can change its layout information without informing this render object.


void performLayout() {
  final SliverConstraints constraints = this.constraints;
  final double maxExtent = this.maxExtent;
  if (_lastActualScrollOffset != null && // We've laid out at least once to get an initial position, and either
      ((constraints.scrollOffset < _lastActualScrollOffset!) || // we are scrolling back, so should reveal, or
       (_effectiveScrollOffset! < maxExtent))) { // some part of it is visible, so should shrink or reveal as appropriate.
    double delta = _lastActualScrollOffset! - constraints.scrollOffset;

    final bool allowFloatingExpansion = constraints.userScrollDirection == ScrollDirection.forward
      || (_lastStartedScrollDirection != null && _lastStartedScrollDirection == ScrollDirection.forward);
    if (allowFloatingExpansion) {
      if (_effectiveScrollOffset! > maxExtent) {
        // We're scrolled off-screen, but should reveal, so pretend we're just at the limit.
        _effectiveScrollOffset = maxExtent;
    } else {
      if (delta > 0.0) {
        // Disallow the expansion. (But allow shrinking, i.e. delta < 0.0 is fine.)
        delta = 0.0;
    _effectiveScrollOffset = clampDouble(_effectiveScrollOffset! - delta, 0.0, constraints.scrollOffset);
  } else {
    _effectiveScrollOffset = constraints.scrollOffset;
  final bool overlapsContent = _effectiveScrollOffset! < constraints.scrollOffset;

    overlapsContent: overlapsContent,
  _childPosition = updateGeometry();
  _lastActualScrollOffset = constraints.scrollOffset;