forked from TechieBlossom/flutter-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomPainterDemo.dart
76 lines (65 loc) · 2.2 KB
/
CustomPainterDemo.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import 'package:flutter/material.dart';
Color mainBGColor = Color(0xFF652A78);
Color redColor = Color(0xFFDE3C10);
Color purpleColor = Color(0xFF8132AD);
Color cyan = Color(0xFF99D5E5);
Color orange = Color(0xFFE97A4D);
class CustomPaintDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: CustomPaint(
painter: MyCustomPainter(),
child: Container(
height: 500.0,
),
),
),
);
}
}
class MyCustomPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint();
Path mainBGPath = Path();
mainBGPath.addRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height));
paint.color = mainBGColor;
canvas.drawPath(mainBGPath, paint);
Path purplePath = Path();
purplePath.lineTo(size.width * .45, 0);
purplePath.quadraticBezierTo(size.width * .25, size.height * .3, 0, size.height * 0.55);
purplePath.close();
paint.color = purpleColor;
canvas.drawPath(purplePath, paint);
Path redPath = Path();
redPath.moveTo(size.width * 0.9 , 0.0);
redPath.quadraticBezierTo(size.width * .5, size.height * 0.1, 0, size.height * 0.85);
redPath.lineTo(0, size.height);
redPath.lineTo(size.width * 0.25, size.height);
redPath.quadraticBezierTo(size.width * .5, size.height * 0.7, size.width, size.height * 0.6);
redPath.lineTo(size.width, 0.0);
redPath.close();
paint.color = redColor;
canvas.drawPath(redPath, paint);
Path orangePath = Path();
orangePath.moveTo(0, size.height * 0.75);
orangePath.quadraticBezierTo(size.width * .25, size.height * 0.85, size.width * .40, size.height);
orangePath.lineTo(0, size.height);
orangePath.close();
paint.color = orange;
canvas.drawPath(orangePath, paint);
Path trianglePath = Path();
trianglePath.lineTo(size.width *.25, 0);
trianglePath.lineTo(0, size.height * .25);
trianglePath.close();
paint.color = cyan;
canvas.drawPath(trianglePath, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return oldDelegate != this;
}
}