Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
feat(example): show perfect shape in red
Browse files Browse the repository at this point in the history
  • Loading branch information
adil192 committed Oct 11, 2023
1 parent 56336a8 commit 03cade4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions example/lib/canvas_draw.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:interactive_shape_recognition/interactive_shape_recognition.dart';

class CanvasDraw extends StatefulWidget {
const CanvasDraw({
super.key,
required this.detectedShape,
required this.onDraw,
});

final ValueNotifier<DetectedShape?> detectedShape;
final void Function(List<Offset>) onDraw;

@override
Expand Down Expand Up @@ -62,6 +65,28 @@ class _CanvasDrawPainter extends CustomPainter {
for (var i = 0; i < state.points.length - 1; i++) {
canvas.drawLine(state.points[i], state.points[i + 1], paint);
}

final detectedShape = state.widget.detectedShape.value;
final shapePaint = Paint()
..color = Colors.red.withOpacity(0.5)
..strokeWidth = 2
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;

switch (detectedShape?.shape) {
case null:
case Shape.unknown:
break;
case Shape.circle:
final (radius, center) = detectedShape!.generateCircle();
canvas.drawCircle(center, radius, shapePaint);
case Shape.rectangle:
final rect = detectedShape!.generateRectangle();
canvas.drawRect(rect, shapePaint);
case Shape.line:
final (start, end) = detectedShape!.generateLine();
canvas.drawLine(start, end, shapePaint);
}
}

@override
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MyApp extends StatelessWidget {
),
body: SizedBox.expand(
child: CanvasDraw(
detectedShape: detectedShape,
onDraw: (points) {
if (pointDebounce == null || !pointDebounce!.isActive) {
pointDebounce = Timer(const Duration(milliseconds: 10), () {
Expand Down

0 comments on commit 03cade4

Please sign in to comment.