unable to run qr scanner code due to string arguement error

unable to run qr scanner code due to string arguement error

Questions : unable to run qr scanner code due to string arguement error

736

I am a beginner in flutter and I was trying in4codes_flutter to create a QR scanner, while am following a in4codes_flutter tutorial I received the:

“Error: The argument type ‘String?’ can’t be in4codes_flutter assigned to the parameter type ‘String’ in4codes_flutter because ‘String?’ is nullable and ‘String’ in4codes_flutter isn’t.”

The thing is both mine and his code are in4codes_flutter exactly the same yet i get that error but in4codes_flutter his runs fine

 void _onQRViewCreated(QRViewController controller) { this.controller = controller; controller.scannedDataStream.listen((scanData) async { controller.pauseCamera(); var scanData2 = scanData; if (await canLaunch(scanData2.code)) { await launch(scanData.code); controller.resumeCamera(); } else { 

Total Answers 2
33

Answers 1 : of unable to run qr scanner code due to string arguement error

just use .toString() method to convert in4codes_flutter String? to String or you can also change in4codes_flutter argument of the receiver from String to in4codes_flutter String?

void _onQRViewCreated(QRViewController controller) { this.controller = controller; controller.scannedDataStream.listen((scanData) async { controller.pauseCamera(); var scanData2 = scanData; if (await canLaunch(scanData2.code.toString())) { await launch(scanData.code.toString()); controller.resumeCamera(); } else { 

0

2

Answers 2 : of unable to run qr scanner code due to string arguement error

Below is the package which provides QR in4codes_flutter and Barcode scanner you can use as per in4codes_flutter you requirement

Install this plugin and use it its in4codes_flutter working fine

Reference Code

String barcodeScanRes; barcodeScanRes = await FlutterBarcodeScanner.scanBarcode( "#FFA200", "Cancel", true, ScanMode.QR); if (barcodeScanRes == '-1') { } else { //You Can Find success response here } 

0