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 center = Offset(size.width / 2, size.height / 2);

  final startAngle = startAngleDeg * _radiansPerDegree;
  final itemSpacing =
      totalArchDeg / (idItems.length + (isAddExtraFakeItem ? 0 : -1));

  //distance from center circle to item top left
  final itemCenterDistance =
      config.centerWidgetRadius + config.innerSpacing + config.itemRadius;

  for (int i = 0; i < idItems.length; i++) {
    final idItem = idItems[i];

    final id = idItem.id;

    final itemSize = layoutChild(id, BoxConstraints.loose(size));
    final itemAngle = startAngle +
        i * itemSpacing * _radiansPerDegree * (isClockWise ? 1 : -1);

    final itemXAxis = center.dx -
        itemSize.width / 2 +
        itemCenterDistance * Math.cos(itemAngle);

    final itemYAxis = center.dy -
        itemSize.height / 2 +
        itemCenterDistance * Math.sin(itemAngle);

    positionChild(id, Offset(itemXAxis, itemYAxis));
  }

  final centerLayoutId = centerCircleLayoutId;
  if (centerLayoutId != null) {
    final centerSize =
        layoutChild(centerLayoutId.id, BoxConstraints.loose(size));
    positionChild(
      centerLayoutId.id,
      Offset(
        center.dx - centerSize.width / 2,
        center.dy - centerSize.height / 2,
      ),
    );
  }
}