From 1c7df8d8c1f764c90fa9cf7f0eae8a089763c0af Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 18 Mar 2026 09:46:08 +0300 Subject: [PATCH] scan qr code revert. --- lib/views/widgets/qr/scan_qr.dart | 58 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/views/widgets/qr/scan_qr.dart b/lib/views/widgets/qr/scan_qr.dart index def01183..bbef7f70 100644 --- a/lib/views/widgets/qr/scan_qr.dart +++ b/lib/views/widgets/qr/scan_qr.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:mobile_scanner/mobile_scanner.dart'; import 'package:qr_code_scanner_plus/qr_code_scanner_plus.dart'; import '../buttons/app_icon_button.dart'; @@ -14,7 +15,10 @@ class ScanQr extends StatefulWidget { class _ScanQrState extends State { // Barcode result; - QRViewController? _controller; + // QRViewController? _controller; + + MobileScannerController? controller; + bool _scanDone = false; final GlobalKey qrKey = GlobalKey(debugLabel: 'QR_scanner'); @@ -22,19 +26,34 @@ class _ScanQrState extends State { // is android, or resume the camera if the platform is iOS. @override - void reassemble() { - super.reassemble(); - if (Platform.isAndroid) { - _controller?.pauseCamera(); - } else if (Platform.isIOS) { - _controller?.resumeCamera(); - } + void initState() { + // TODO: implement initState + super.initState(); + controller = MobileScannerController( + detectionSpeed: DetectionSpeed.noDuplicates, + formats: [], + returnImage: false, + torchEnabled: false, + invertImage: false, + autoZoom: true, + ); } + // + // @override + // void reassemble() { + // super.reassemble(); + // if (Platform.isAndroid) { + // controller?.pauseCamera(); + // } else if (Platform.isIOS) { + // _controller?.resumeCamera(); + // } + // } + @override void dispose() { super.dispose(); - _controller?.dispose(); + // _controller?.dispose(); } @override @@ -42,20 +61,15 @@ class _ScanQrState extends State { return Scaffold( body: Stack( children: [ - QRView( - key: qrKey, - onQRViewCreated: (QRViewController controller) { - setState(() { - _controller = controller; - }); - controller.scannedDataStream.listen((scanData) { - if (!_scanDone) { - _scanDone = true; - Navigator.of(context).pop(scanData.code); - } - }); + MobileScanner( + tapToFocus: true, + controller: controller, + onDetect: (result) { + if (!_scanDone) { + _scanDone = true; + Navigator.of(context).pop(result.barcodes.first.rawValue); + } }, - overlay: QrScannerOverlayShape(borderColor: Colors.red, borderRadius: 10, borderLength: 30, borderWidth: 10, cutOutSize: 280), ), SafeArea( child: Padding(