performLayout method

  1. @override
void performLayout()
override

the main child would be laid out firstly then, other actions would be laid out based on _ComputedSizes the main child would not have a position for its SlidableBoxData

Implementation

@override
void performLayout() {
  assert(childCount <= 3,
      'RenderSlidable only support 3 children at most. That would be a pre [SlideActionPanel], the main child, and a post [SlideActionPanel].');

  final computedSize = _layoutMainChild();

  RenderBox? child = firstChild;

  while (child != null) {
    final childParentData = child.parentData as SlidableBoxData;

    if (childParentData.position != null) {
      final actionConstraints = switch (childParentData.position!) {
        ActionPosition.pre => computedSize.constraintsForPreAction,
        ActionPosition.post => computedSize.constraintsForPostAction,
      };

      child.layout(actionConstraints, parentUsesSize: false);

      childParentData.offset = switch (childParentData.position!) {
        ActionPosition.pre => Offset.zero,
        ActionPosition.post => computedSize.getTopLeftForPostAction(axis),
      };
    }

    child = childParentData.nextSibling;
  }

  size = computedSize.size;
  controller.layoutSize = computedSize.getLayoutSize(axis, maxSlideThreshold);
}