LCOV - code coverage report
Current view: top level - src - painter.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 18 18 100.0 %
Date: 2020-02-24 15:58:08 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/cupertino.dart';
       2             : import 'package:flutter/material.dart';
       3             : 
       4             : import 'convex_shape.dart';
       5             : import 'reused_gradient.dart';
       6             : 
       7             : /// Custom painter to draw the [ConvexNotchedRectangle] into canvas.
       8             : class ConvexPainter extends CustomPainter {
       9             :   final _paint = Paint();
      10             :   final _shadowPaint = Paint();
      11             :   final _shape = ConvexNotchedRectangle();
      12             :   final ReusedGradient _gradient = ReusedGradient();
      13             : 
      14             :   /// Width of the convex shape.
      15             :   final double width;
      16             : 
      17             :   /// Height of the convex shape.
      18             :   final double height;
      19             : 
      20             :   /// Position in vertical which describe the offset of shape.
      21             :   final double top;
      22             : 
      23             :   /// Position in horizontal which describe the offset of shape.
      24             :   final Animation<double> leftPercent;
      25             : 
      26           1 :   ConvexPainter({
      27             :     this.top,
      28             :     this.width,
      29             :     this.height,
      30             :     this.leftPercent = const AlwaysStoppedAnimation<double>(0.5),
      31             :     Color color = Colors.white,
      32             :     Color shadowColor = Colors.black38,
      33             :     double sigma = 2,
      34             :     Gradient gradient,
      35           1 :   }) : super(repaint: leftPercent) {
      36           2 :     _paint..color = color;
      37           1 :     _shadowPaint
      38           1 :       ..color = shadowColor
      39           2 :       ..maskFilter = MaskFilter.blur(BlurStyle.outer, sigma);
      40           2 :     _gradient.gradient = gradient;
      41             :   }
      42             : 
      43           1 :   @override
      44             :   void paint(Canvas canvas, Size size) {
      45           3 :     Rect host = Rect.fromLTWH(0, 0, size.width, size.height);
      46           1 :     Rect guest = Rect.fromLTWH(
      47          10 :         size.width * leftPercent.value - width / 2, top, width, height);
      48           3 :     _gradient.updateWith(_paint, size: host);
      49           2 :     Path path = _shape.getOuterPath(host, guest);
      50           2 :     canvas.drawPath(path, _shadowPaint);
      51           2 :     canvas.drawPath(path, _paint);
      52             :   }
      53             : 
      54           1 :   @override
      55             :   bool shouldRepaint(ConvexPainter oldDelegate) {
      56           5 :     return oldDelegate.leftPercent.value != leftPercent.value ||
      57           3 :         oldDelegate._paint != _paint;
      58             :   }
      59             : }

Generated by: LCOV version 1.14