What method draws on the canvas in CustomPainter?
The paint() method is where you use the Canvas to draw.
Create custom graphics and visual effects
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
CustomPaint lets you draw anything you want on the screen using a Canvas object. You can draw circles, rectangles, lines, arcs, paths, and even complex shapes pixel by pixel. This is useful for charts, custom progress indicators, signature pads, drawing apps, or any visual element that standard widgets cannot create.
1// Custom painter2class CirclePainter extends CustomPainter {3@override4void paint(Canvas canvas, Size size) {5final paint = Paint()6..color = Colors.blue7..style = PaintingStyle.fill;89// Draw filled circle10canvas.drawCircle(11Offset(size.width / 2, size.height / 2),1250,13paint,14);1516// Draw outline17paint.style = PaintingStyle.stroke;18paint.strokeWidth = 3;19paint.color = Colors.red;20canvas.drawCircle(21Offset(size.width / 2, size.height / 2),2270,23paint,24);25}2627@override28bool shouldRepaint(covariant CustomPainter oldDelegate) => false;29}3031// Use it32CustomPaint(33painter: CirclePainter(),34size: Size(200, 200),35)
Flutter supports advanced visual effects like glassmorphism (frosted glass look), gradient borders, and shadow layering. These effects combine multiple widgets together. For example, a glass effect uses ClipRRect to clip the area, BackdropFilter to blur what is behind it, and a semi-transparent Container on top to create the frosted look.
1// Glass morphism effect2Container(3decoration: BoxDecoration(4borderRadius: BorderRadius.circular(20),5color: Colors.white.withValues(alpha: 0.2),6border: Border.all(color: Colors.white.withValues(alpha: 0.3)),7),8child: ClipRRect(9borderRadius: BorderRadius.circular(20),10child: BackdropFilter(11filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),12child: content,13),14),15)1617// Gradient borders18Container(19decoration: BoxDecoration(20gradient: LinearGradient(21colors: [Colors.purple, Colors.blue],22),23borderRadius: BorderRadius.circular(16),24),25padding: EdgeInsets.all(3), // Border width26child: Container(27decoration: BoxDecoration(28color: Colors.white,29borderRadius: BorderRadius.circular(14),30),31child: content,32),33)
Use CustomPaint when standard widgets cannot represent the required visual language, such as progress rings, charts, signatures, or game-like overlays.
Prefer regular widgets first. Move to custom painting only when the problem truly needs canvas-level control.
Create custom graphics and visual effects. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Connect each concept to real app features you can build.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Connect this lesson to separation of concerns so your codebase stays maintainable as it grows.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
The paint() method is where you use the Canvas to draw.
shouldRepaint returns true if the painter has changed and needs to redraw, optimizing performance.
BackdropFilter with ImageFilter.blur creates a blur effect behind its child (glass morphism).
PaintingStyle.stroke draws only the border/outline. PaintingStyle.fill fills the entire shape.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue