This is a widget, that have function that triggers each time we scan qr code.
import 'package:qr_code_scanner/qr_code_scanner.dart';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
flex: 4,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: 300,
),
),
),
In function I want to navigate to next screen.
void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
});
}
Problem here is that that listen event trigger many times, is it possible to stop this function after first successfully scan data? I try with
controller.scannedDataStream.first;
But that return empty string and not triggers when real data are scanned.
I need to click 40 times to go back from Second Route to return to QR scanner widget. Thanks!
for future reference i found pausing the camera works better :)
void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {
qrText = scanData;
SecondPageRoute();
});
}
SecondPageRoute() async {
controller?.pauseCamera();
var value = await Navigator.push(context,
MaterialPageRoute(builder: (context) {
return SecondPage(qrText);
})).then((value) => controller.resumeCamera());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With