ParallaxRainPainter constructor Null safety

ParallaxRainPainter(
  1. {required int numberOfDrops,
  2. required Size parentSize,
  3. required double dropFallSpeed,
  4. required int numberOfLayers,
  5. required bool trail,
  6. required double dropHeight,
  7. required double dropWidth,
  8. required List<Color> dropColors,
  9. required double trailStartFraction,
  10. required double distanceBetweenLayers,
  11. required ValueNotifier notifier}
)

Implementation

ParallaxRainPainter(
    {required this.numberOfDrops,
    required this.parentSize,
    required this.dropFallSpeed,
    required this.numberOfLayers,
    required this.trail,
    required this.dropHeight,
    required this.dropWidth,
    required this.dropColors,
    required this.trailStartFraction,
    required this.distanceBetweenLayers,
    required ValueNotifier notifier})
    : super(repaint: notifier) {
  paintObject = Paint()
    ..color = dropColors[0]
    ..style = PaintingStyle.fill;

  double effectiveLayer;
  for (int i = 0; i < this.numberOfDrops; i++) {
    double x = random.nextDouble() * parentSize.width;
    double y = random.nextDouble() * parentSize.height;

    // Keeping [widget.numberOfLayers] layers for the parallax effect, the base values are for the layer furthest behind
    int layerNumber =
        random.nextInt(numberOfLayers); // 0 is the layer furthest behind
    effectiveLayer = layerNumber * distanceBetweenLayers;
    dropSize = new Size(dropWidth, dropHeight);
    dropList.add(
      new Drop(
          drop: Offset(x, y) &
              Size(
                dropSize.width + (dropSize.width * effectiveLayer),
                dropSize.height + (dropSize.height * effectiveLayer),
              ),
          dropSpeed:
              this.dropFallSpeed + (this.dropFallSpeed * effectiveLayer),
          dropLayer: layerNumber,
          dropColor: dropColors[random.nextInt(dropColors.length)]),
    );
  }
}