Last active
September 23, 2024 01:40
-
-
Save lesliearkorful/052dc86c5e3a5d4453902126ac62a458 to your computer and use it in GitHub Desktop.
Google's "G" logo purely drawn in Flutter
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
// written by @lesliearkorful | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: GoogleLogo(), | |
); | |
} | |
} | |
class GoogleLogo extends StatelessWidget { | |
final double size; | |
const GoogleLogo({Key? key, this.size = 300}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
alignment: Alignment.center, | |
color: Colors.white, | |
child: CustomPaint(painter: GoogleLogoPainter(), size: Size.square(size)), | |
); | |
} | |
} | |
class GoogleLogoPainter extends CustomPainter { | |
@override | |
bool shouldRepaint(_) => true; | |
@override | |
void paint(Canvas canvas, Size size) { | |
final length = size.width; | |
final verticalOffset = (size.height / 2) - (length / 2); | |
final bounds = Offset(0, verticalOffset) & Size.square(length); | |
final center = bounds.center; | |
final arcThickness = size.width / 4.5; | |
final paint = Paint() | |
..style = PaintingStyle.stroke | |
..strokeWidth = arcThickness; | |
void drawArc(double startAngle, double sweepAngle, Color color) { | |
final _paint = paint..color = color; | |
canvas.drawArc(bounds, startAngle, sweepAngle, false, _paint); | |
} | |
drawArc(3.5, 1.9, Colors.red); | |
drawArc(2.5, 1.0, Colors.amber); | |
drawArc(0.9, 1.6, Colors.green.shade600); | |
drawArc(-0.18, 1.1, Colors.blue.shade600); | |
canvas.drawRect( | |
Rect.fromLTRB( | |
center.dx, | |
center.dy - (arcThickness / 2), | |
bounds.centerRight.dx + (arcThickness / 2) - 4, | |
bounds.centerRight.dy + (arcThickness / 2), | |
), | |
paint | |
..color = Colors.blue.shade600 | |
..style = PaintingStyle.fill | |
..strokeWidth = 0, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works! thanks boss