I have the following in the build widget and because it's in a stream it's always calling the callback, how do I stop the stream once there is data so it only happens once. I tried to dispose of it but that did not work. I also don't have a cancel method.
// Conroller and handles the listening
void _onQRViewCreated(QRViewController controller) {
setState(() {
this.controller = controller;
});
// Might need to add onError
controller.scannedDataStream.listen((scanData) {
setState(() {
result = scanData;
widget.qrSuccess(result.code);
});
});
}