performLayout method

  1. @override
void performLayout()
override

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.

Implementation

@override
void performLayout() {
  //只有最后一个位置 只要一个view 其他位置都要两个 头部 展开后要显示第一个 一个旋转的背面,一个展开后的首页  0--.5
  //中间的 上下旋转的背面,展开后显示的正面  -.5--.5
  //最后一个 只要展开显示正面  -.5-0
  // firstChild 为正常view; 不旋转 展开的时候以及之后要显示出来,
  // lastChild 旋转的view; 可能是背部可能是正面 最下面的位置为 正面

  if (spinProgress == -.5) {
    ///折叠起来之后就不需要占位置了
    firstChild!.layout(constraints, parentUsesSize: true);
    if (highProgress == null || highProgress == 0) {
      size = Size.zero;
    } else {
      //不可见的时候 先增加高度
      _originalSize = size = firstChild!.size;
      if (highProgress != null && highProgress! > 0) {
        size = Size(size.width, highProgress! * size.height);
      }
    }
    return;
  }

  // cos a * 斜边 = 夹角边长(邻边)
  firstChild!.layout(constraints, parentUsesSize: true);
  _originalSize = size = firstChild!.size;
  firstChild!.layout(BoxConstraints.tight(size), parentUsesSize: false);

  if (childCount == 2) {
    lastChild!.layout(BoxConstraints.tight(size), parentUsesSize: true);
  }
  if (highProgress != null && highProgress! > 0) {
    size = Size(size.width, highProgress! * size.height);
  } else {
    //没有高度变化的控制就自己变化高度
    if (spinProgress < 0) {
      size = Size(size.width, Cubic(0.775, 0.685, 0.12, 1.05).transform(math.cos(spinProgress.abs() * pi)) * size.height);
    }
  }
}