Created
September 21, 2021 16:09
-
-
Save yeasin50/ad326ddafd976bae1fd224bc4b3bef5b to your computer and use it in GitHub Desktop.
priceTag using CustomPainter
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
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: const Scaffold( | |
body: Center( | |
child: PriceTag(), | |
), | |
), | |
); | |
} | |
} | |
class PriceTag extends StatelessWidget { | |
const PriceTag({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
height: 100, | |
width: 300, | |
child: CustomPaint( | |
painter: PriceTagPaint(), | |
child: const Center( | |
child: Text( | |
"Coolant", | |
style: TextStyle( | |
fontSize: 44, | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class PriceTagPaint extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
Paint paint = Paint() | |
..color = Colors.green | |
..strokeCap = StrokeCap.round | |
..style = PaintingStyle.fill; | |
Path path = Path(); | |
path | |
..moveTo(0, size.height * .5) | |
..lineTo(size.width * .13, 0) | |
..lineTo(size.width, 0) | |
..lineTo(size.width, size.height) | |
..lineTo(size.width * .13, size.height) | |
..lineTo(0, size.height * .5) | |
..close(); | |
canvas.drawPath(path, paint); | |
//* Circle | |
canvas.drawCircle( | |
Offset(size.width * .13, size.height * .5), | |
size.height * .15, | |
paint..color = Colors.white, | |
); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment