performLayout method

  1. @override
void performLayout(
  1. Size size
)
override

Override this method to lay out and position all children given this widget's size.

This method must call layoutChild for each child. It should also specify the final position of each child with positionChild.

Implementation

@override
void performLayout(Size size) {
  final BoxConstraints constrains = BoxConstraints(
    maxWidth: size.width,
    maxHeight: size.height,
  );

  final dividerHalf =
      showDraggableDivider ? PlutoDualGrid.dividerWidth / 2 : 0;

  final dividerWidth = dividerHalf * 2;

  double gridAWidth = showDraggableDivider
      ? display.offset == null
          ? display.gridAWidth(constrains) - dividerHalf
          : display.offset! - dividerHalf
      : display.gridAWidth(constrains) - dividerHalf;
  double gridBWidth = size.width - gridAWidth - dividerWidth;

  if (!isLTR) {
    final savedGridBWidth = gridBWidth;
    gridBWidth = gridAWidth;
    gridAWidth = savedGridBWidth;
  }

  if (gridAWidth < 0) {
    gridAWidth = 0;
  } else if (gridAWidth > size.width - dividerWidth) {
    gridAWidth = size.width - dividerWidth;
  }

  if (gridBWidth < 0) {
    gridBWidth = 0;
  } else if (gridBWidth > size.width - dividerWidth) {
    gridBWidth = size.width - dividerWidth;
  }

  if (hasChild(_PlutoDualGridId.gridA)) {
    layoutChild(
      _PlutoDualGridId.gridA,
      BoxConstraints.tight(
        Size(gridAWidth, size.height),
      ),
    );

    final double posX = isLTR ? 0 : gridBWidth + dividerWidth;

    positionChild(_PlutoDualGridId.gridA, Offset(posX, 0));
  }

  if (hasChild(_PlutoDualGridId.divider)) {
    layoutChild(
      _PlutoDualGridId.divider,
      BoxConstraints.tight(
        Size(PlutoDualGrid.dividerWidth, size.height),
      ),
    );

    final double posX = isLTR ? gridAWidth : gridBWidth;

    positionChild(_PlutoDualGridId.divider, Offset(posX, 0));
  }

  if (hasChild(_PlutoDualGridId.gridB)) {
    layoutChild(
      _PlutoDualGridId.gridB,
      BoxConstraints.tight(
        Size(gridBWidth, size.height),
      ),
    );

    final double posX = isLTR ? gridAWidth + dividerWidth : 0;

    positionChild(_PlutoDualGridId.gridB, Offset(posX, 0));
  }
}