mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 10:38:41 +00:00
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
58 lines
1.5 KiB
Dart
58 lines
1.5 KiB
Dart
import 'dart:ui';
|
|
import 'package:camera/camera.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_mlkit_barcode_scanning/google_mlkit_barcode_scanning.dart';
|
|
import 'coordinates_translator.dart';
|
|
|
|
class BarcodeDetectorPainter extends CustomPainter {
|
|
BarcodeDetectorPainter(
|
|
this.barcodes,
|
|
this.imageSize,
|
|
this.rotation,
|
|
this.cameraLensDirection,
|
|
);
|
|
|
|
final List<Barcode> barcodes;
|
|
final Size imageSize;
|
|
final InputImageRotation rotation;
|
|
final CameraLensDirection cameraLensDirection;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final paint = Paint()
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 3.0
|
|
..color = Colors.lightGreenAccent;
|
|
|
|
for (final barcode in barcodes) {
|
|
final cornerPoints = <Offset>[];
|
|
for (final point in barcode.cornerPoints) {
|
|
final x = translateX(
|
|
point.x.toDouble(),
|
|
size,
|
|
imageSize,
|
|
rotation,
|
|
cameraLensDirection,
|
|
);
|
|
final y = translateY(
|
|
point.y.toDouble(),
|
|
size,
|
|
imageSize,
|
|
rotation,
|
|
cameraLensDirection,
|
|
);
|
|
|
|
cornerPoints.add(Offset(x, y));
|
|
}
|
|
|
|
cornerPoints.add(cornerPoints.first);
|
|
canvas.drawPoints(PointMode.polygon, cornerPoints, paint);
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(BarcodeDetectorPainter oldDelegate) {
|
|
return oldDelegate.imageSize != imageSize ||
|
|
oldDelegate.barcodes != barcodes;
|
|
}
|
|
}
|