getTestContainers static method

List<Container> getTestContainers(
  1. int num,
  2. double childSize, {
  3. bool rainbow = false,
})

Returns a list of circular containers for testing purposes.

The number of containers is defined by the num parameter.

Implementation

static List<Container> getTestContainers(int num, double childSize,
    {bool rainbow = false}) {
  List<Container> containers = [];
  for (int i = 0; i < num; i++) {
    // Calculate the segment length
    int segmentLength = num ~/ 3;
    int r = 0, g = 0, b = 0;

    if (rainbow) {
      if (i < segmentLength) {
        // Red to Green
        r = 255 - (255 * i ~/ segmentLength);
        g = 255 * i ~/ segmentLength;
        b = 0;
      } else if (i < segmentLength * 2) {
        // Green to Blue
        int j = i - segmentLength;
        g = 255 - (255 * j ~/ segmentLength);
        b = 255 * j ~/ segmentLength;
      } else {
        // Blue to Red
        int j = i - segmentLength * 2;
        b = 255 - (255 * j ~/ segmentLength);
        r = 255 * j ~/ segmentLength;
      }
    }

    containers.add(Container(
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        color: rainbow ? Color.fromARGB(255, r, g, b) : Colors.green,
      ),
      child: Center(
        child: Text(
          (i + 1).toString(),
          style: const TextStyle(
            color: Colors.white,
          ),
        ),
      ),
    ));
  }
  return containers;
}