update method

void update(
  1. double dt
)

Implementation

void update(double dt) {
  if (dropList.isEmpty || _lastSize == null) return;

  final double maxHeight = _lastSize!.height;
  final double maxWidth = _lastSize!.width;
  final double speedMultiplier = 60 * dt;

  for (int i = 0; i < dropList.length; i++) {
    final CustomDrop currentDrop = dropList[i];
    final double currentTop = currentDrop.drop.top;
    final double currentSpeed = currentDrop.dropSpeed;
    final double currentLeft = currentDrop.drop.left;

    final double move = currentSpeed * speedMultiplier;

    if (currentTop + move < maxHeight) {
      currentDrop.drop = Offset(currentLeft, currentTop + move) &
          currentDrop.drop.size;
    } else {
      final int layer = random.nextInt(numberOfLayers);
      final double effectiveLayer = layer * distanceBetweenLayers;
      dropSize = Size(dropWidth, dropHeight);

      currentDrop.drop = Offset(random.nextDouble() * maxWidth,
              -(dropSize.height + (dropSize.height * effectiveLayer))) &
          Size(
              dropSize.width + (dropSize.width * effectiveLayer),
              dropSize.height + (dropSize.height * effectiveLayer));
      currentDrop.dropSpeed =
          dropFallSpeed + (dropFallSpeed * effectiveLayer);
      currentDrop.dropLayer = layer;
      currentDrop.dropColor = dropColors[random.nextInt(dropColors.length)];
    }
  }
}