@@ -12,26 +12,84 @@ class LightPaintRect extends CustomPainter {
12
12
final double offset;
13
13
final double radius;
14
14
15
- late Paint _paintFocus;
16
-
17
15
LightPaintRect ({
18
16
required this .progress,
19
17
required this .target,
20
18
this .colorShadow = Colors .black,
21
19
this .opacityShadow = 0.8 ,
22
20
this .offset = 10 ,
23
21
this .radius = 10 ,
24
- }) : assert (opacityShadow >= 0 && opacityShadow <= 1 ) {
25
- _paintFocus = Paint ()
26
- ..color = Colors .transparent
27
- ..blendMode = BlendMode .clear;
22
+ }) : assert (opacityShadow >= 0 && opacityShadow <= 1 );
23
+
24
+ static Path _drawRectHole (
25
+ Size canvasSize,
26
+ double x,
27
+ double y,
28
+ double w,
29
+ double h,
30
+ ) {
31
+ return Path ()
32
+ ..moveTo (0 , 0 )
33
+ ..lineTo (0 , y)
34
+ ..lineTo (x + w, y)
35
+ ..lineTo (x + w, y + h)
36
+ ..lineTo (x, y + h)
37
+ ..lineTo (x, y)
38
+ ..lineTo (0 , y)
39
+ ..lineTo (0 , canvasSize.height)
40
+ ..lineTo (canvasSize.width, canvasSize.height)
41
+ ..lineTo (canvasSize.width, 0 )
42
+ ..close ();
43
+ }
44
+
45
+ static Path _drawRRectHole (
46
+ Size canvasSize,
47
+ double x,
48
+ double y,
49
+ double w,
50
+ double h,
51
+ double radius,
52
+ ) {
53
+ double diameter = radius * 2 ;
54
+
55
+ return Path ()
56
+ ..moveTo (0 , 0 )
57
+ ..lineTo (0 , y + radius)
58
+ ..arcTo (
59
+ Rect .fromLTWH (x, y, diameter, diameter),
60
+ pi,
61
+ pi / 2 ,
62
+ false ,
63
+ )
64
+ ..arcTo (
65
+ Rect .fromLTWH (x + w - diameter, y, diameter, diameter),
66
+ 3 * pi / 2 ,
67
+ pi / 2 ,
68
+ false ,
69
+ )
70
+ ..arcTo (
71
+ Rect .fromLTWH (x + w - diameter, y + h - diameter, diameter, diameter),
72
+ 0 ,
73
+ pi / 2 ,
74
+ false ,
75
+ )
76
+ ..arcTo (
77
+ Rect .fromLTWH (x, y + h - diameter, diameter, diameter),
78
+ pi / 2 ,
79
+ pi / 2 ,
80
+ false ,
81
+ )
82
+ ..lineTo (x, y + radius)
83
+ ..lineTo (0 , y + radius)
84
+ ..lineTo (0 , canvasSize.height)
85
+ ..lineTo (canvasSize.width, canvasSize.height)
86
+ ..lineTo (canvasSize.width, 0 )
87
+ ..close ();
28
88
}
29
89
30
90
@override
31
91
void paint (Canvas canvas, Size size) {
32
92
if (target.offset == Offset .zero) return ;
33
- canvas.saveLayer (Offset .zero & size, Paint ());
34
- canvas.drawColor (colorShadow.withOpacity (opacityShadow), BlendMode .dstATop);
35
93
36
94
var maxSize = max (size.width, size.height) +
37
95
max (target.size.width, target.size.height);
@@ -44,12 +102,14 @@ class LightPaintRect extends CustomPainter {
44
102
45
103
double h = maxSize * (1 - progress) + target.size.height + offset;
46
104
47
- RRect rrect = RRect .fromRectAndRadius (
48
- Rect .fromLTWH (x, y, w, h),
49
- Radius .circular (radius),
105
+ canvas.drawPath (
106
+ radius > 0
107
+ ? _drawRRectHole (size, x, y, w, h, radius)
108
+ : _drawRectHole (size, x, y, w, h),
109
+ Paint ()
110
+ ..style = PaintingStyle .fill
111
+ ..color = colorShadow.withOpacity (opacityShadow),
50
112
);
51
- canvas.drawRRect (rrect, _paintFocus);
52
- canvas.restore ();
53
113
}
54
114
55
115
@override
0 commit comments