Skip to content

Instantly share code, notes, and snippets.

@lukaswhite
Created April 20, 2025 09:19
Show Gist options
  • Save lukaswhite/81cb548c3d9e640b394b7353d20e823f to your computer and use it in GitHub Desktop.
Save lukaswhite/81cb548c3d9e640b394b7353d20e823f to your computer and use it in GitHub Desktop.
Displaying an SVG in Flutter using a Custom Painter
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(body: Center(child: HomeIcon())),
);
}
}
class HomeIcon extends StatelessWidget {
const HomeIcon();
@override
Widget build(BuildContext context) {
return CustomPaint(
size: Size(48, 48),
painter: _Painter(),
);
}
}
class _Painter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Path path_0 = Path();
path_0.moveTo(20,40);
path_0.lineTo(20,28);
path_0.lineTo(28,28);
path_0.lineTo(28,40);
path_0.lineTo(38,40);
path_0.lineTo(38,24);
path_0.lineTo(44,24);
path_0.lineTo(24,6);
path_0.lineTo(4,24);
path_0.lineTo(10,24);
path_0.lineTo(10,40);
path_0.close();
Paint paint_0_fill = Paint()..style=PaintingStyle.fill;
paint_0_fill.color = Color(0xff000000).withOpacity(1.0);
canvas.drawPath(path_0,paint_0_fill);
Path path_1 = Path();
path_1.moveTo(0,0);
path_1.lineTo(48,0);
path_1.lineTo(48,48);
path_1.lineTo(0,48);
path_1.close();
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment