Skip to content

Instantly share code, notes, and snippets.

@CarloTerracciano
Created September 2, 2024 10:29
Show Gist options
  • Save CarloTerracciano/f396ddef53944d857a71ba40bd57167e to your computer and use it in GitHub Desktop.
Save CarloTerracciano/f396ddef53944d857a71ba40bd57167e to your computer and use it in GitHub Desktop.
Generated code from pixels2flutter.dev
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(
size: Size(100, 100),
painter: YellowShapePainter(),
),
),
),
);
}
}
class YellowShapePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.yellow
..style = PaintingStyle.fill;
final path = Path()
..moveTo(size.width * 0.2, 0)
..lineTo(size.width, 0)
..lineTo(size.width, size.height)
..lineTo(0, size.height)
..lineTo(0, size.height * 0.2)
..arcToPoint(
Offset(size.width * 0.2, 0),
radius: Radius.circular(size.width * 0.2),
clockwise: false,
)
..close();
canvas.drawPath(path, paint);
final crossPaint = Paint()
..color = Colors.white
..strokeWidth = 10
..strokeCap = StrokeCap.round;
final centerX = size.width / 2;
final centerY = size.height / 2;
final crossSize = size.width * 0.4;
canvas.drawLine(
Offset(centerX - crossSize / 2, centerY - crossSize / 2),
Offset(centerX + crossSize / 2, centerY + crossSize / 2),
crossPaint,
);
canvas.drawLine(
Offset(centerX + crossSize / 2, centerY - crossSize / 2),
Offset(centerX - crossSize / 2, centerY + crossSize / 2),
crossPaint,
);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment