Skip to content

Instantly share code, notes, and snippets.

@tejaswini-dev-techie
Last active February 20, 2024 06:19
Show Gist options
  • Save tejaswini-dev-techie/912a9515759ba5a9e4216fdb87379b5c to your computer and use it in GitHub Desktop.
Save tejaswini-dev-techie/912a9515759ba5a9e4216fdb87379b5c to your computer and use it in GitHub Desktop.
Understanding Custom Painters in Flutter: Creating Ribbon Tag
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: const Color.fromARGB(255, 18, 32, 47),
),
debugShowCheckedModeBanner: false,
home: const Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return CustomPaint(
size: const Size(296, 34),
painter: RibbonTagCustomPainter(),
);
}
}
class RibbonTagCustomPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Path path_0 = Path();
path_0.moveTo(0.306256 * size.width / 296.058, 32.2446);
path_0.cubicTo(
-0.39425 * size.width / 296.058,
32.9335,
0.184367 * size.width / 296.058,
34,
1.25859 * size.width / 296.058,
34);
path_0.lineTo(294.741 * size.width / 296.058, 34);
path_0.cubicTo(
295.817 * size.width / 296.058,
34,
296.395 * size.width / 296.058,
32.931,
295.692 * size.width / 296.058,
32.2427);
path_0.lineTo(280.784 * size.width / 296.058, 17.6548);
path_0.cubicTo(
280.375 * size.width / 296.058,
17.2551,
280.376 * size.width / 296.058,
16.6622,
280.786 * size.width / 296.058,
16.2633);
path_0.lineTo(295.681 * size.width / 296.058, 1.75926);
path_0.cubicTo(296.387 * size.width / 296.058, 1.07147,
295.81 * size.width / 296.058, 0, 294.733 * size.width / 296.058, 0);
path_0.lineTo(1.26737 * size.width / 296.058, 0);
path_0.cubicTo(
0.191708 * size.width / 296.058,
0,
-0.386394 * size.width / 296.058,
1.06898,
0.317022 * size.width / 296.058,
1.75731);
path_0.lineTo(15.143 * size.width / 296.058, 16.2652);
path_0.cubicTo(
15.55 * size.width / 296.058,
16.6635,
15.5508 * size.width / 296.058,
17.2538,
15.145 * size.width / 296.058,
17.6529);
path_0.lineTo(0.306256 * size.width / 296.058, 32.2446);
path_0.close();
Paint paint_0_fill = Paint()..style = PaintingStyle.fill;
paint_0_fill.color = Colors.white.withOpacity(1.0);
canvas.drawPath(path_0, paint_0_fill);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment