Skip to content

Instantly share code, notes, and snippets.

@lesliearkorful
Last active September 23, 2024 01:40
Show Gist options
  • Save lesliearkorful/052dc86c5e3a5d4453902126ac62a458 to your computer and use it in GitHub Desktop.
Save lesliearkorful/052dc86c5e3a5d4453902126ac62a458 to your computer and use it in GitHub Desktop.
Google's "G" logo purely drawn in Flutter
// 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,
);
}
}
@samtuga1
Copy link

Beautifully done bro!

@Iremide-ds
Copy link

Nice

@codeByAdam
Copy link

Super cool!

@nathfavour
Copy link

Works! thanks boss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment