gradient function

LinearGradient gradient({
  1. required List<Color> colors,
  2. List<double>? stops,
  3. Direction direction = Direction.toRight,
})

生成渐变 >>>

Implementation

LinearGradient gradient(
    {required List<Color> colors,
    List<double>? stops,
    Direction direction = Direction.toRight}) {
  late AlignmentGeometry begin;
  late AlignmentGeometry end;
  switch (direction) {
    case Direction.toDown:
      begin = Alignment.topLeft;
      end = Alignment.bottomLeft;
      break;
    case Direction.toUp:
      begin = Alignment.bottomLeft;
      end = Alignment.topLeft;
      break;
    case Direction.toRight:
      begin = Alignment.topLeft;
      end = Alignment.topRight;
      break;
    case Direction.toLeft:
      begin = Alignment.topRight;
      end = Alignment.topLeft;
      break;
    case Direction.toTopLeft:
      begin = Alignment.bottomRight;
      end = Alignment.topLeft;
      break;
    case Direction.toTopRight:
      begin = Alignment.bottomLeft;
      end = Alignment.topRight;
      break;
    case Direction.toBottomLeft:
      begin = Alignment.topRight;
      end = Alignment.bottomLeft;
      break;
    case Direction.toBottomRight:
      begin = Alignment.topLeft;
      end = Alignment.bottomRight;
      break;
  }

  return LinearGradient(colors: colors, stops: stops, begin: begin, end: end);
}