01 | import 'package:flutter/material.dart' ; |
02 |
03 | void main() => runApp(MyApp()); |
04 |
05 | class MyApp extends StatelessWidget { |
06 | @override |
07 | Widget build(BuildContext context) { |
08 | return MaterialApp( |
09 | title: 'override重构' , |
10 | home: Scaffold( |
11 | appBar: AppBar( |
12 | title: Text( 'override重构' ), |
13 | ), |
14 | body: Center( |
15 | child: SizedBox( |
16 | width: 500.0, |
17 | height: 500.0, |
18 | child: CustomPaint( |
19 | painter: CirclePainter(), |
20 | child: Center( |
21 | child: Text( |
22 | '绘制圆' , |
23 | style: TextStyle( |
24 | fontSize: 38.0, |
25 | fontWeight: FontWeight.bold, |
26 | ), |
27 | ), |
28 | ), |
29 | ), |
30 | ), |
31 | ), |
32 | ), |
33 | ); |
34 | } |
35 | } |
36 |
37 | class CirclePainter extends CustomPainter { |
38 | Paint _paint = Paint() |
39 | ..color = Colors.grey |
40 | ..strokeCap = StrokeCap.square |
41 | ..isAntiAlias = true |
42 | ..strokeWidth = 3.0 |
43 | ..style = PaintingStyle.stroke; |
44 |
45 | @override |
46 | void paint(Canvas canvas, Size size) { |
47 | canvas.drawCircle(Offset(200.0, 150.0), 150.0, _paint); |
48 | } |
49 |
50 | @override |
51 | bool shouldRepaint(CustomPainter oldDelegate) { |
52 | return false ; |
53 | } |
54 | } |