Created
November 28, 2023 14:03
-
-
Save obumnwabude/0396fb0766acfac63b695dac8b16dcc1 to your computer and use it in GitHub Desktop.
CustomPaint equivalent of the five point star svg at Wikipedia https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg
This file contains 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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: CustomPaint( | |
painter: StarPainter(), | |
size: const Size(255, 240), | |
), | |
), | |
), | |
); | |
} | |
} | |
class StarPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
// d="m25,1 6,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z" | |
canvas.drawPath( | |
Path() | |
..relativeMoveTo(25, 1) | |
..relativeLineTo(6, 17) | |
..relativeLineTo(18, 0) | |
..relativeLineTo(-14, 11) | |
..relativeLineTo(5, 17) | |
..relativeLineTo(-15, -10) | |
..relativeLineTo(-15, 10) | |
..relativeLineTo(5, -17) | |
..relativeLineTo(-14, -11) | |
..relativeLineTo(18, 0) | |
..close(), | |
Paint() | |
..color = Colors.black | |
..style = PaintingStyle.stroke | |
..strokeWidth = 2, | |
); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment