Skip to content

Instantly share code, notes, and snippets.

@aarjan
Created November 8, 2022 10:41
Show Gist options
  • Save aarjan/de79f378816a8b5ba5c3b62490b3d89e to your computer and use it in GitHub Desktop.
Save aarjan/de79f378816a8b5ba5c3b62490b3d89e to your computer and use it in GitHub Desktop.
Sunflower example
import 'package:flutter/material.dart';
void main() {
runApp(HomeScreen());
}
class CardClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(size.width, 0);
path.lineTo(size.width, size.height * 1);
path.quadraticBezierTo(size.width * .5, size.height * .7, 0, size.height);
path.lineTo(0, 0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper old) => false;
}
class ProfileClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(size.width, 0);
path.lineTo(size.width, size.height * .35);
path.quadraticBezierTo(size.width * .5, size.height, 0, size.height*.35);
path.lineTo(0, 0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper old) => false;
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
children: [
ClipPath(
clipper: CardClipper(),
child: Container(
width: 250,
height: 250,
color: Colors.blue,
),
),
const SizedBox(height: 20),
ClipPath(
clipper: ProfileClipper(),
child: Container(
width: 250,
height: 250,
color: Colors.red,
),
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment