/// Created by Haoyi on 2020/12/29

part of 'tips.dart';

class TipsPainter extends CustomPainter {
  final CustomClipper<Path> clipper;

/*  final gradient = LinearGradient(
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
    colors: <Color>[Color(0xFFDADAFB), Color(0xFFFFFFFF)],
  );*/

  final gradient;
  final backgroundColor;
  final List<BoxShadow> shadows = [];

  final _paint = Paint()
    ..isAntiAlias = true
    ..style = PaintingStyle.fill;

  TipsPainter({required this.clipper, this.backgroundColor, this.gradient, List<BoxShadow> shadows = const <BoxShadow>[]}) {
    this.shadows.addAll(shadows);
  }

  @override
  void paint(Canvas canvas, Size size) {
    final path = clipper.getClip(size);

    for (var shadow in shadows) {
      final paint = shadow.toPaint();
      canvas.save();
      canvas.translate(shadow.offset.dx, shadow.offset.dy);
      canvas.drawPath(path, paint);
      canvas.restore();
    }

    if (gradient != null) {
      _paint.shader = gradient.createShader(Rect.fromLTWH(0, 0, size.width, size.height));
    } else if (backgroundColor != null) {
      _paint.color = backgroundColor;
    } else {
      _paint.color = Colors.red;
    }
    // _paint.shader = gradient.createShader(Rect.fromLTWH(0, 0, size.width, size.height));
    canvas.drawPath(path, _paint);

    // canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), _paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return false;
  }
}
