11import 'package:flutter/material.dart' ;
22import '../app/shapes.dart' ;
33import 'independent/event_listenable_builder.dart' ;
4- import 'shape_widget.dart' ;
54
65class DrawingBoard extends StatelessWidget {
76 final Shapes shapes;
@@ -15,19 +14,25 @@ class DrawingBoard extends StatelessWidget {
1514
1615 @override
1716 Widget build (BuildContext context) {
18- return GestureDetector (
19- onTapDown: (e) => addShape (e.localPosition),
20- child: Container (
21- color: Color (0xff1f1f1f ),
22- child: EventListenableBuilder (
23- event: shapes.onAddShapeEvent,
24- builder: (_) {
25- return Stack (
26- children: [
27- for (final shape in shapes) ShapeWidget (shape: shape),
28- ],
29- );
30- },
17+ return Listener (
18+ onPointerMove: (e) => addShape (e.localPosition),
19+ child: GestureDetector (
20+ onTapDown: (e) => addShape (e.localPosition),
21+ child: Container (
22+ color: Color (0xff1f1f1f ),
23+ child: EventListenableBuilder (
24+ event: shapes.onAddShapeEvent,
25+ builder: (_) {
26+ return LayoutBuilder (
27+ builder: (_, constraints) {
28+ return CustomPaint (
29+ size: Size (constraints.maxWidth, constraints.maxHeight),
30+ painter: ShapesPainter (shapes),
31+ );
32+ },
33+ );
34+ },
35+ ),
3136 ),
3237 ),
3338 );
@@ -37,3 +42,24 @@ class DrawingBoard extends StatelessWidget {
3742 onClick (position.dx, position.dy);
3843 }
3944}
45+
46+ class ShapesPainter extends CustomPainter {
47+ final Shapes shapes;
48+
49+ ShapesPainter (this .shapes);
50+
51+ @override
52+ void paint (Canvas canvas, Size _) {
53+ for (final shape in shapes) {
54+ canvas.save ();
55+ canvas.translate (shape.x, shape.y);
56+ shape.paint (canvas);
57+ canvas.restore ();
58+ }
59+ }
60+
61+ @override
62+ bool shouldRepaint (covariant CustomPainter _) {
63+ return false ;
64+ }
65+ }
0 commit comments