CustomPaint Widget
Project Preview
- Interested in seeing the live demo? Click here to explore.
- Want to view the source code? Visit the project on GitHub.
Code Snippet
import 'package:flutter/material.dart';
class CustomPaintWidget extends StatelessWidget {
const CustomPaintWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("CustomPaint Widget"),
),
body: Container(
color: Colors.black,
padding: const EdgeInsets.all(20.0),
child: Center(
child: CustomPaint(
painter: DemoPainter(),
child: const Text(
'This is Pac-Man',
style: TextStyle(
color: Colors.black,
backgroundColor: Colors.white54,
fontSize: 30,
),
),
),
),
),
);
}
}
class DemoPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var center = size / 2;
var paint = Paint()..color = Colors.yellow;
canvas.drawArc(
Rect.fromCenter(
center: Offset(center.width, center.height),
width: 250,
height: 250,
),
0.4,
2 * 3.14 - 0.8,
true,
paint,
);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}