I'm having a problem getting a variable after the function runs.
I have to read a qr code and then put the qr code in a text field, but when i try to read it gets the default variable text, and only gets the right qr code when i try to read for the seccond time.
Here is the qr reader function:
Future<void> scanQR() async {
String barcodeScanRes;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.QR);
print(barcodeScanRes);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_scanBarcode = barcodeScanRes;
});
}
Here the button to run the function and then put the qr on the controller:
onPressed: () {
scanQR();
setState(() {
_codprodController.text = _scanBarcode;
});
},
//on the first time i try it shows "unknown" that is the _scanBarCode default text instead of the qr i read
I guess the problem is the "_codprodController.text = _scanBarcode;" that its not runnig after (but together) the scanQR() but i dont know hot to fix.