I am a beginner in flutter and I was trying to create a QR scanner, while am following a tutorial I received the:
"Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't."
The thing is both mine and his code are exactly the same yet i get that error but 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 {
CodePudding user response:
Below is the package which provides QR and Barcode scanner you can use as per you requirement
Install this plugin and use it its 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
}
Happy Coding!
CodePudding user response:
just use .toString() method to convert String? to String or you can also change argument of the receiver from String to 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 {