Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created February 28, 2021 16:28
Show Gist options
  • Save pingbird/8eb8a74e9c3132f0038e98b2b478ffb0 to your computer and use it in GitHub Desktop.
Save pingbird/8eb8a74e9c3132f0038e98b2b478ffb0 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: MyPainter(),
child: SizedBox(width: 400, height: 200),
);
}
}
class MyPainter extends CustomPainter {
void paint(canvas, size) {
final span = TextSpan(style: TextStyle(color: Colors.white, fontSize: 80, fontWeight: FontWeight.bold), text: "Glitchy");
final tp = TextPainter(text: span, textAlign: TextAlign.center, textDirection: TextDirection.ltr);
tp.layout(minWidth: size.width);
final glitchPath = Path()..addRect(
Rect.fromLTWH(0, 40, size.width, 20),
);
final nonGlitchPath = Path.combine(
PathOperation.difference,
Path()..addRect(
Rect.fromLTWH(0, 0, size.width, size.height),
),
glitchPath,
);
canvas.save();
canvas.translate(
0, size.height / 2 - tp.height / 2,
);
canvas.save();
canvas.clipPath(glitchPath);
tp.paint(canvas, Offset(-5, 0));
canvas.restore();
canvas.save();
canvas.clipPath(nonGlitchPath);
tp.paint(canvas, Offset.zero);
canvas.restore();
canvas.restore();
}
bool shouldRepaint(_) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment