我正在制作条形码扫描功能。相机进给正在设置_currentImage
。
// CameraView.dart
CameraImage _currentImage;
CameraImage takePhoto() => _currentImage;
void imageStream(CameraImage image) async {
print("_currentImage is set with " + image.toString()); // keeps saying it sets 'currentImage'
this._currentImage = image;
}
后来我takePhoto
从按钮按下处理程序调用并调用'setState'为空......
void pressedShowBarcodeOnScreenButton() async {
var image = this.cameraView.takePhoto();
if (image == null) {
print(// occurs after having called empty 'setState' every time button is pressed
"image was null, maybe it is not possible to take images this fast!");
return;
}
var barcode =
await VisionService.getInstance() // is not producing any errors
.analyzeBarcode(ImageUtils.toAbstractImage(image));
if (Utils.isNullOrEmpty(barcode)) {
return;
}
print("got barcode: " + barcode); // prints all barcodes ok, but stops doing so when calling 'setState'
setState(() {
// Makes it so that 'currentImage' is null at all times, despite continuously set by imageStream given from log
//this.scannedBarcodes = [...this.scannedBarcodes, barcode]; // my intention eventual to update a list
});
}
我怀疑这可能是由于一些潜在的飞镖行为,或者有某种错误?为什么setState
呼叫阻止我访问_currentImage
- 或为什么被阻止设置imageStream()
?