-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathclippath.dart
57 lines (49 loc) · 1.14 KB
/
clippath.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
import 'package:flutter/material.dart';
class MyClipPath extends StatefulWidget {
const MyClipPath({Key? key}) : super(key: key);
@override
State<MyClipPath> createState() => _MyClipPathState();
}
class _MyClipPathState extends State<MyClipPath> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ClipPath(
clipper: CustomClipPath(),
child: Container(
color: Colors.red,
height: 400,
child: const Center(
child: Text(
'Clip Path',
style: TextStyle(color: Colors.white, fontSize: 40),
),
),
),
),
);
}
}
class CustomClipPath extends CustomClipper<Path> {
@override
Path getClip(Size size) {
double w = size.width;
double h = size.height;
final path = Path();
// (0, 0) // 1. point
path.lineTo(0, h); // 2. Point
path.quadraticBezierTo(
w * 0.5,
h - 100,
w,
h,
); // 3. Point
path.lineTo(w, 0); // 4. Point
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}