1

I am using this package package for scanning barcode. It works fine but after successfully scan I want to close the camera. I searched for the solution but no solution worked in my case. Here is my code.

 try { FlutterBarcodeScanner.getBarcodeStreamReceiver( '#ff6666', 'Cancel', true, ScanMode.BARCODE)! .listen((data) { print(data); }); } on PlatformException { // barcodeScanRes = 'Failed to get platform version.'; } } 
1
  • Did you got the solution? In case of continous scanning, how to stop after a successful scan. Commented Jun 29, 2023 at 9:22

1 Answer 1

1

you can close scan page by adding this line to your code

if (barcodeScanRes != null){ print(barcodeScanRes); // this will send your scan result to previous page // or you can navigate to other page after scan success Navigator.pop(context, barcodeScanRes); } 
String barcodeScanRes; // put this variable in statefull widget Future<void> scanQR() async { try { barcodeScanRes = await FlutterBarcodeScanner.scanBarcode( '#ff6666', 'Cancel', true, ScanMode.QR); // add this line to close scanner or naivigate to other page if (barcodeScanRes != null){ print(barcodeScanRes); Navigator.pop(context, barcodeScanRes); } } on PlatformException { barcodeScanRes = 'Failed to get platform version.'; } if (!mounted) return; setState(() { _scanBarcode = barcodeScanRes; }); } 

or if you want to pause the camera after scan, you can use this package https://pub.dev/packages/qr_code_scanner

Sign up to request clarification or add additional context in comments.

1 Comment

This is single scan. Question is for "getBarcodeStreamReceiver". I am also searching for an answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.