import 'package:flutter/material.dart';
class CustomPaintCircleScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Custom Painter Demo'),
),
body: Center(
child: CustomPaint(
size: Size(100, 100),
painter: CirclePainter(),
),
),
);
}
}
class CirclePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.blue
..style = PaintingStyle.fill;
final center = Offset(size.width / 2, size.height / 2);
canvas.drawCircle(center, 50, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}We created a CirclePainter class extending CustomPainter. Inside the paint method, we made a Paint object with blue color and fill style. Then we calculated the center of the canvas using the size parameter. Finally, we drew a circle with radius 50 at the center using canvas.drawCircle. The shouldRepaint returns false because the painting does not change dynamically.
The CustomPaint widget uses this painter and sets its size to 100x100, so the circle fits nicely in the center of the screen.