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);

  double _itemSpacing = totalArchDeg / idItems.length;

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

    final id = idItem.id;

    final buttonSize = layoutChild(id, BoxConstraints.loose(size));
    final actualIndex = i;
    final startAngle = startAngleDeg * _radiansPerDegree;
    final itemAngle = startAngle +
        actualIndex *
            _itemSpacing *
            _radiansPerDegree *
            (isClockWise ? 1 : -1);

    positionChild(
      id,
      Offset(
        (center.dx - buttonSize.width / 2) +
            (radius) * Math.cos(itemAngle), //x axis
        (center.dy - buttonSize.height / 2) +
            (radius) * Math.sin(itemAngle), //y axis
      ),
    );
  }

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