Created
October 23, 2025 14:58
-
-
Save emmanuelrosa/fda0de10bde602987ef5f11dcf981d7e to your computer and use it in GitHub Desktop.
ZTM CustomPainter lesson, with fixed mouth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:math' as math; | |
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Art Class', | |
| theme: ThemeData( | |
| colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | |
| ), | |
| home: const MyHomePage(), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatelessWidget { | |
| const MyHomePage({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
| title: Text('Art Class'), | |
| ), | |
| body: CustomPaint( | |
| size: MediaQuery.of(context).size, | |
| painter: MyPainter(), | |
| ), | |
| ); | |
| } | |
| } | |
| class MyPainter extends CustomPainter { | |
| @override | |
| void paint(Canvas canvas, Size size) { | |
| final linePaint = Paint()..strokeWidth = 10; | |
| canvas.drawLine(const Offset(50, 150), const Offset(150, 220), linePaint); | |
| canvas.drawLine( | |
| Offset(size.width - 50, 150), | |
| Offset(size.width - 150, 220), | |
| linePaint, | |
| ); | |
| final circlePaint = Paint(); | |
| canvas.drawCircle(const Offset(100, 250), 20, circlePaint); | |
| canvas.drawCircle(Offset(size.width - 100, 250), 20, circlePaint); | |
| final arcPaint = Paint() | |
| ..strokeWidth = 10 | |
| ..style = PaintingStyle.stroke; | |
| final rect = Rect.fromLTWH((size.width / 2) - 110, 350, 220, 300); | |
| canvas.drawArc(rect, math.pi, math.pi, true, arcPaint); | |
| } | |
| @override | |
| bool shouldRepaint(covariant CustomPainter oldDelegate) => true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment