Last active
January 5, 2023 12:40
-
-
Save CoderNamedHendrick/f7884dde1760e2120f8ba81e66f94d99 to your computer and use it in GitHub Desktop.
Receipt clipper showing making some cuts in a widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
darkTheme: ThemeData.dark(), | |
theme: ThemeData.light(), | |
home: const MyHomePage(), | |
debugShowCheckedModeBanner: false, | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Flutter app'), | |
), | |
body: Column( | |
children: [ | |
ClipPath( | |
clipper: ReceiptClipper(), | |
child: Container( | |
padding: const EdgeInsets.all(40), | |
alignment: Alignment.topCenter, | |
width: 300, | |
height: 600, | |
decoration: BoxDecoration( | |
color: Theme.of(context).backgroundColor, | |
borderRadius: BorderRadius.circular(12)), | |
), | |
) | |
], | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
print('Zapp!'); | |
}, | |
backgroundColor: Colors.yellow[700], | |
child: Icon( | |
Icons.bolt, | |
color: Colors.black, | |
), | |
), | |
); | |
} | |
} | |
class ReceiptClipper extends CustomClipper<Path> { | |
@override | |
Path getClip(Size size) { | |
double yPosition = size.height / 3; | |
Path path = Path() | |
..moveTo(0, 0) | |
..lineTo(0, yPosition) | |
..quadraticBezierTo(20, yPosition + 15, 0, yPosition + 30) | |
..lineTo(0, size.height) | |
..lineTo(size.width, size.height) | |
..lineTo(size.width, yPosition + 30) | |
..quadraticBezierTo( | |
size.width - 20, yPosition + 15, size.width, yPosition) | |
..lineTo(size.width, 0) | |
..close(); | |
return path; | |
} | |
@override | |
bool shouldReclip(covariant CustomClipper<Path> oldClipper) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment