So i create a qr Scanner and i manage to finished it and give me a result, but as i print the result it give me
'Instance of 'Barcode'
feedback
Here's my code
Future _openScanner(BuildContext context) async {
final result = await Navigator.push(context, MaterialPageRoute(builder: (c) => Scanner()));
_result = result.toString();
}
How I show on my app
Text(
_result != null ? _result : 'Hi, Raisa',
style: TextStyle(
color: Color(
0xFFE1C884),
// fontFamily: 'Saveur',
fontWeight: FontWeight
.bold,
fontSize: 20.sp
),
)
My QR View Code
QRView(
key: _qrKey,
overlay: QrScannerOverlayShape(borderColor: Colors.white),
onQRViewCreated: (QRViewController controller) {
this._controller = controller;
controller.scannedDataStream.listen((val) {
// print(val.toString());
if (mounted) {
_controller.dispose();
Navigator.pop(context,val);
}
});
}),
CodePudding user response:
You should do something like this:
Future _openScanner(BuildContext context) async {
final result = await Navigator.push(context, MaterialPageRoute(builder: (c) => Scanner()));
_result = result.getValue;
}
class Barcode{
String? value;
...
String get getValue{
return value;
}
...
}
QRView(
key: _qrKey,
overlay: QrScannerOverlayShape(borderColor: Colors.white),
onQRViewCreated: (QRViewController controller) {
this._controller = controller;
controller.scannedDataStream.listen((val) {
// print(val.toString());
if (mounted) {
_controller.dispose();
value = val;
Navigator.pop(context);
}
});
}),
}
CodePudding user response:
There's an incorrection there
- add this :
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
Barcode result;
- add this on the QRview
QRView(
key: _qrKey,
overlay: QrScannerOverlayShape(borderColor: Colors.white),
onQRViewCreated: (QRViewController controller) {
this._controller = controller;
controller.scannedDataStream.listen((val) {
// print(val.toString());
if (mounted) {
_controller.dispose();
value = val; //this
Navigator.pop(context);
}
});
}),
}
when about to show or print
a. if you want to print the type of the Barcode simply add (.format) b. if you want to print the code of the barcode simply add (.code)