Flutter Decoded.
esc

Type to search lessons, steps and concepts.

↑ ↓ move · ↵ open · esc close
Support
Language
Made with ♥ by Aman Singh · Support the projectNot affiliated with Google. Flutter and Dart are trademarks of Google LLC. Videos belong to their creators.
Course46 lessons
›01. Dart Foundations0/4
  1. Variables, Types & Null Safety
  2. Functions & Classes
  3. Futures, async/await & Streams
  4. Records, Patterns & Sealed Classes
›02. Flutter Fundamentals0/4
  1. Everything Is a Widget
  2. Stateless vs Stateful Widgets
  3. Widgets, Elements & RenderObjects
  4. Project Structure & Hot Reload
›03. Layout & UI0/6
  1. Constraints Go Down, Sizes Go Up
  2. Rows, Columns & Flex
  3. Stack, Positioned & Layering
  4. Lists, Grids & Slivers
  5. Responsive & Adaptive Design
  6. Theming with Material 3
›04. Interaction & Navigation0/4
  1. Taps, Gestures & Input
  2. Forms & Validation
  3. Navigator & Routes
  4. go_router & Deep Links
›05. State Management0/5
  1. Ephemeral vs App State
  2. InheritedWidget & Provider
  3. Riverpod
  4. The BLoC Pattern
  5. Choosing an Approach
›06. Data & Backend0/6
  1. HTTP & JSON
  2. Dio: Interceptors & Retries
  3. Saving Data Locally
  4. Firebase: Auth & Firestore
  5. Backend Options: Supabase, Appwrite & More
  6. Isolates & Heavy Work
›07. App Architecture0/3
  1. UI Layer & Data Layer
  2. Repositories & Dependency Injection
  3. Clean Architecture & Folder Structure
›08. Motion & Performance0/4
  1. Implicit Animations
  2. Explicit Animations
  3. Custom Painting
  4. Performance & DevTools
›09. Testing & Shipping0/4
  1. Unit, Widget & Integration Tests
  2. Environments & Flavors
  3. CI/CD & Releasing
  4. Flutter on the Web & Desktop
›10. Release Automation & Code Push0/6
  1. Codemagic: Your First Pipeline
  2. Codemagic: Code Signing
  3. Codemagic: Publish to the Stores
  4. Shorebird: Code Push for Flutter
  5. Shorebird: Safe Patching
  6. Shorebird in Codemagic
Progress0 / 46
Browse all videos →
08. Motion & Performance / Lesson 3 / 4

Custom Painting

Draw your own graphics, like charts, rings and clocks, on a Canvas with CustomPainter.

6 minIntermediate5 steps
progress_ring.dart
1class RingPainter extends CustomPainter {
2 RingPainter(this.progress);
3 final double progress;
4
5 @override
6 void paint(Canvas canvas, Size size) {
7 final center = size.center(Offset.zero);
8 final radius = size.shortestSide / 2 - 8;
9 final paint = Paint()
10 ..style = PaintingStyle.stroke
11 ..strokeWidth = 12
12 ..strokeCap = StrokeCap.round
13 ..color = Colors.blue;
14
15 canvas.drawArc(
16 Rect.fromCircle(center: center, radius: radius),
17 -pi / 2, // start at 12 o'clock
18 2 * pi * progress, // sweep
19 false,
20 paint,
21 );
22 }
23
24 @override
25 bool shouldRepaint(RingPainter old) => old.progress != progress;
26}
27
28CustomPaint(size: const Size(120, 120), painter: RingPainter(0.7))
Live simulatorCustomPaint ring
65%
parent rebuilds0
paint() calls1
shouldRepaint(old) => old.progress != progress;
Step 1 / 5

CustomPaint hosts a painter

CustomPaint is a widget that gives a CustomPainter a canvas of a given size.

You'll learn

  • CustomPaint and CustomPainter
  • Canvas coordinates and Size
  • Paint styles
  • Efficient repaints

Read the official docs

CustomPainter API ↗Canvas API ↗

Watch it built

16:31
Flutter Custom Painter Tutorial || Clock AppCodeX · 83K views
Game Development with Flutter & FlameCodeX · 41K views
1 / 5
← → step · Space pause · R replay