Skip to content

Instantly share code, notes, and snippets.

@rydmike
Created August 15, 2022 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rydmike/54745b57f16caff3a3f49ebee7329d1b to your computer and use it in GitHub Desktop.
Save rydmike/54745b57f16caff3a3f49ebee7329d1b to your computer and use it in GitHub Desktop.
Fancy Clubs V-Logo
import 'dart:math' as math;
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
const ColorScheme schemeLight = ColorScheme.light(
primary: Color(0xFF0E8479),
secondary: Color(0xFFFF5E2B),
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'V-Logo',
theme: ThemeData.from(
useMaterial3: true,
colorScheme: schemeLight,
),
home: const LogoPage(),
);
}
}
class LogoPage extends StatelessWidget {
const LogoPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('V-Logo'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: AspectRatio(
aspectRatio: 1.0,
child: VLogo(
size: double.infinity,
foregroundColor: schemeLight.primary,
backgroundColor: schemeLight.secondary,
),
),
),
),
);
}
}
/// VLogo represents the logo used in this app
class VLogo extends StatelessWidget {
const VLogo({
Key? key,
required this.size,
this.foregroundColor = const Color.fromARGB(255, 1, 156, 100),
this.backgroundColor = const Color.fromARGB(255, 243, 80, 33),
}) : super(key: key);
final double size;
final Color foregroundColor;
final Color backgroundColor;
@override
Widget build(BuildContext context) {
return CustomPaint(
size: Size(size, size),
painter: _LogoPainter(foregroundColor, backgroundColor),
);
}
}
class _LogoPainter extends CustomPainter {
const _LogoPainter(
this.foregroundColor,
this.backgroundColor,
);
final Color foregroundColor;
final Color backgroundColor;
@override
void paint(Canvas canvas, Size size) {
final Paint paint0 = Paint()
..color = backgroundColor
..style = PaintingStyle.fill
..strokeWidth = 1;
paint0.shader = ui.Gradient.linear(
Offset(size.width * 0.50, size.height * 0.05),
Offset(size.width * 0.95, size.height * 0.95),
<Color>[
backgroundColor.brighten(20),
backgroundColor.lighten(10),
backgroundColor,
backgroundColor.darken(10),
backgroundColor.darken(20),
],
<double>[0, 0.2, 0.5, 0.9, 1],
);
final Path path0 = Path();
path0.moveTo(size.width * 0.5003965, size.height * 0.0491882);
path0.cubicTo(
size.width * 0.6821000,
size.height * 0.0498000,
size.width * 0.9529900,
size.height * 0.1758600,
size.width * 0.9518302,
size.height * 0.5006218);
path0.cubicTo(
size.width * 0.9529900,
size.height * 0.6816600,
size.width * 0.8175900,
size.height * 0.9527000,
size.width * 0.5003965,
size.height * 0.9520555);
path0.cubicTo(
size.width * 0.3209600,
size.height * 0.9527000,
size.width * 0.0501300,
size.height * 0.8172000,
size.width * 0.0489629,
size.height * 0.5006218);
path0.cubicTo(
size.width * 0.0501300,
size.height * 0.3206700,
size.width * 0.1856400,
size.height * 0.0498000,
size.width * 0.5003965,
size.height * 0.0491882);
path0.close();
canvas.drawPath(path0, paint0);
final Paint paint1 = Paint()
..color = foregroundColor
..style = PaintingStyle.fill
..strokeWidth = 7.19;
final Path path1 = Path();
path1.moveTo(size.width * 0.2700000, size.height * 0.9300000);
path1.quadraticBezierTo(size.width * 0.1768000, size.height * 0.6442200,
size.width * 0.0800000, size.height * 0.3900000);
path1.cubicTo(
size.width * 0.0067100,
size.height * 0.1239100,
size.width * 0.0940200,
size.height * 0.0239500,
size.width * 0.1900000,
size.height * 0.0900000);
path1.quadraticBezierTo(size.width * 0.3519000, size.height * 0.2431500,
size.width * 0.2900000, size.height * 0.8800000);
path1.quadraticBezierTo(size.width * 0.5453900, size.height * 0.7337900,
size.width * 0.6381819, size.height * 0.3509091);
path1.cubicTo(
size.width * 0.6863500,
size.height * 0.1742500,
size.width * 0.8152300,
size.height * 0.0174100,
size.width * 0.9100000,
size.height * 0.0800000);
path1.cubicTo(
size.width * 0.9976100,
size.height * 0.1972500,
size.width * 0.9434600,
size.height * 0.3436600,
size.width * 0.8981819,
size.height * 0.4409091);
path1.quadraticBezierTo(size.width * 0.7378900, size.height * 0.7534100,
size.width * 0.2700000, size.height * 0.9300000);
path1.close();
canvas.drawPath(path1, paint1);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
/// Extensions on [Color] to brighten, lighten, darken and blend colors and
/// can get a shade for gradients.
///
/// Some of the extensions are rewrites of TinyColor's functions
/// https://pub.dev/packages/tinycolor. The TinyColor algorithms have also
/// been modified to use Flutter's HSLColor class instead of the custom one in
/// the TinyColor lib. The functions from TinyColor re-implemented as Color
/// extensions here are [brighten], [lighten] and [darken]. They are used
/// for color calculations in FlexColorScheme, but also exposed for reuse.
extension FlexColorExtensions on Color {
/// Brightens the color with the given integer percentage amount.
/// Defaults to 10%.
Color brighten([final int amount = 10]) {
if (amount <= 0) return this;
if (amount > 100) return Colors.white;
final Color color = Color.fromARGB(
alpha,
math.max(0, math.min(255, red - (255 * -(amount / 100)).round())),
math.max(0, math.min(255, green - (255 * -(amount / 100)).round())),
math.max(0, math.min(255, blue - (255 * -(amount / 100)).round())),
);
return color;
}
/// Lightens the color with the given integer percentage amount.
/// Defaults to 10%.
Color lighten([final int amount = 10]) {
if (amount <= 0) return this;
if (amount > 100) return Colors.white;
// HSLColor returns saturation 1 for black, we want 0 instead to be able
// lighten black color up along the grey scale from black.
final HSLColor hsl = this == const Color(0xFF000000)
? HSLColor.fromColor(this).withSaturation(0)
: HSLColor.fromColor(this);
return hsl
.withLightness(math.min(1, math.max(0, hsl.lightness + amount / 100)))
.toColor();
}
/// Darkens the color with the given integer percentage amount.
/// Defaults to 10%.
Color darken([final int amount = 10]) {
if (amount <= 0) return this;
if (amount > 100) return Colors.black;
final HSLColor hsl = HSLColor.fromColor(this);
return hsl
.withLightness(math.min(1, math.max(0, hsl.lightness - amount / 100)))
.toColor();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment