Navaron Bracke

fix bug with null scan window; abort if texture is null

... ... @@ -269,7 +269,7 @@ class MobileScannerHandler(
}
private fun updateScanWindow(call: MethodCall, result: MethodChannel.Result) {
mobileScanner!!.scanWindow = call.argument<List<Float>?>("rect")
mobileScanner?.scanWindow = call.argument<List<Float>?>("rect")
result.success(null)
}
... ...
... ... @@ -287,9 +287,19 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
@override
Future<void> updateScanWindow(Rect? window) async {
if (_textureId == null) {
return;
}
List<double>? points;
if (window != null) {
points = [window.left, window.top, window.right, window.bottom];
}
await methodChannel.invokeMethod<void>(
'updateScanWindow',
{'rect': window},
{'rect': points},
);
}
... ...
... ... @@ -288,6 +288,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
await MobileScannerPlatform.instance.setTorchState(newState);
}
/// Update the scan window with the given [window] rectangle.
///
/// If [window] is null, the scan window will be reset to the full camera preview.
Future<void> updateScanWindow(Rect? window) async {
await MobileScannerPlatform.instance.updateScanWindow(window);
}
@override
Future<void> dispose() async {
if (_isDisposed) {
... ...