Skip to content

Commit 73c571a

Browse files
adding custom painter demo code
1 parent 70ef44e commit 73c571a

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

CustomPainterDemo.dart

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

0 commit comments

Comments
 (0)