FaderPainter constructor

FaderPainter({
  1. required Animation<double> animation,
  2. required FaderPainterData data,
})

Creates a FaderPainter object.

This is the painter for full screen color fading animations.

Implementation

FaderPainter({
  required super.animation,
  required this.data,
}) : super(repaint: animation) {
  if (data.colors.isEmpty) {
    throw const EmptyColorListException('`colors` cannot be empty.');
  }

  // Set the colors based on the behavior.
  switch (data.behavior) {
    case FaderBehavior.specifiedOrder:
      _colors = List.from(data.colors);
      break;
    case FaderBehavior.sortedOrder:
      _colors = List.from(data.colors)..sortColors();
      break;
    case FaderBehavior.reverseSortedOrder:
      _colors =
          (List<Color>.from(data.colors)..sortColors()).reversed.toList();
      break;
    case FaderBehavior.random:
      _colors = List.from(data.colors)..add(data.colors.first);
      _colors.shuffle();
      break;
    case FaderBehavior.breathe:
      final List<Color> tempColors2 = List.from(data.colors)..sortColors();
      final List<Color> tempColors1 =
          List.from(tempColors2.reversed.toList());

      tempColors1.insert(0, tempColors1.first);
      tempColors1.removeLast();

      _colors = [...tempColors1, ...tempColors2];
      break;
    case FaderBehavior.pulse:
      final List<Color> tempColors2 = List.from(data.colors)..sortColors();
      final List<Color> tempColors1 =
          List.from(tempColors2.reversed.toList());

      tempColors1.removeLast();
      final Color darkColor = tempColors2.removeLast();

      _colors = [
        ...tempColors1,
        ...tempColors2,
        ...tempColors1,
        ...tempColors2,
        darkColor,
        darkColor,
      ];

      break;
  }
}