Browse Source

qr

10062025_01
Stephane 6 months ago
parent
commit
5b6e9e1cc3
  1. 43
      lib/Components/QrScan.dart

43
lib/Components/QrScan.dart

@ -25,13 +25,14 @@ class _ScanQRPageState extends State<ScanQRPage> {
} }
void _initializeController() { void _initializeController() {
if (!isMobile) { // if (!isMobile) {
setState(() { // setState(() {
_hasError = true; // _hasError = true;
_errorMessage = "Le scanner QR n'est pas disponible sur cette plateforme."; // _errorMessage =
}); // "Le scanner QR n'est pas disponible sur cette plateforme.";
return; // });
} // return;
// }
try { try {
cameraController = MobileScannerController( cameraController = MobileScannerController(
detectionSpeed: DetectionSpeed.noDuplicates, detectionSpeed: DetectionSpeed.noDuplicates,
@ -61,7 +62,9 @@ class _ScanQRPageState extends State<ScanQRPage> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Scanner QR Code'), title: const Text('Scanner QR Code'),
actions: _hasError ? [] : [ actions: _hasError
? []
: [
if (cameraController != null) ...[ if (cameraController != null) ...[
IconButton( IconButton(
color: Colors.white, color: Colors.white,
@ -71,7 +74,8 @@ class _ScanQRPageState extends State<ScanQRPage> {
), ),
IconButton( IconButton(
color: Colors.white, color: Colors.white,
icon: const Icon(Icons.flip_camera_ios, color: Colors.white), icon:
const Icon(Icons.flip_camera_ios, color: Colors.white),
iconSize: 32.0, iconSize: 32.0,
onPressed: () => cameraController!.switchCamera(), onPressed: () => cameraController!.switchCamera(),
), ),
@ -150,7 +154,8 @@ class _ScanQRPageState extends State<ScanQRPage> {
children: [ children: [
const Icon(Icons.error, size: 64, color: Colors.red), const Icon(Icons.error, size: 64, color: Colors.red),
const SizedBox(height: 16), const SizedBox(height: 16),
Text('Erreur: ${error.errorDetails?.message ?? 'Erreur inconnue'}'), Text(
'Erreur: ${error.errorDetails?.message ?? 'Erreur inconnue'}'),
const SizedBox(height: 16), const SizedBox(height: 16),
ElevatedButton( ElevatedButton(
onPressed: () => _initializeController(), onPressed: () => _initializeController(),
@ -236,19 +241,25 @@ class QrScannerOverlay extends CustomPainter {
..style = PaintingStyle.stroke; ..style = PaintingStyle.stroke;
// Coins du scanner // Coins du scanner
_drawCorner(canvas, borderPaint, areaLeft, areaTop, borderLength, true, true); _drawCorner(
_drawCorner(canvas, borderPaint, areaLeft + areaSize, areaTop, borderLength, false, true); canvas, borderPaint, areaLeft, areaTop, borderLength, true, true);
_drawCorner(canvas, borderPaint, areaLeft, areaTop + areaSize, borderLength, true, false); _drawCorner(canvas, borderPaint, areaLeft + areaSize, areaTop, borderLength,
_drawCorner(canvas, borderPaint, areaLeft + areaSize, areaTop + areaSize, borderLength, false, false); false, true);
_drawCorner(canvas, borderPaint, areaLeft, areaTop + areaSize, borderLength,
true, false);
_drawCorner(canvas, borderPaint, areaLeft + areaSize, areaTop + areaSize,
borderLength, false, false);
} }
void _drawCorner(Canvas canvas, Paint paint, double x, double y, double length, bool isLeft, bool isTop) { void _drawCorner(Canvas canvas, Paint paint, double x, double y,
double length, bool isLeft, bool isTop) {
final double horizontalStart = isLeft ? x : x - length; final double horizontalStart = isLeft ? x : x - length;
final double horizontalEnd = isLeft ? x + length : x; final double horizontalEnd = isLeft ? x + length : x;
final double verticalStart = isTop ? y : y - length; final double verticalStart = isTop ? y : y - length;
final double verticalEnd = isTop ? y + length : y; final double verticalEnd = isTop ? y + length : y;
canvas.drawLine(Offset(horizontalStart, y), Offset(horizontalEnd, y), paint); canvas.drawLine(
Offset(horizontalStart, y), Offset(horizontalEnd, y), paint);
canvas.drawLine(Offset(x, verticalStart), Offset(x, verticalEnd), paint); canvas.drawLine(Offset(x, verticalStart), Offset(x, verticalEnd), paint);
} }

Loading…
Cancel
Save