Navaron Bracke

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

@@ -269,7 +269,7 @@ class MobileScannerHandler( @@ -269,7 +269,7 @@ class MobileScannerHandler(
269 } 269 }
270 270
271 private fun updateScanWindow(call: MethodCall, result: MethodChannel.Result) { 271 private fun updateScanWindow(call: MethodCall, result: MethodChannel.Result) {
272 - mobileScanner!!.scanWindow = call.argument<List<Float>?>("rect") 272 + mobileScanner?.scanWindow = call.argument<List<Float>?>("rect")
273 273
274 result.success(null) 274 result.success(null)
275 } 275 }
@@ -287,9 +287,19 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { @@ -287,9 +287,19 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
287 287
288 @override 288 @override
289 Future<void> updateScanWindow(Rect? window) async { 289 Future<void> updateScanWindow(Rect? window) async {
  290 + if (_textureId == null) {
  291 + return;
  292 + }
  293 +
  294 + List<double>? points;
  295 +
  296 + if (window != null) {
  297 + points = [window.left, window.top, window.right, window.bottom];
  298 + }
  299 +
290 await methodChannel.invokeMethod<void>( 300 await methodChannel.invokeMethod<void>(
291 'updateScanWindow', 301 'updateScanWindow',
292 - {'rect': window}, 302 + {'rect': points},
293 ); 303 );
294 } 304 }
295 305
@@ -288,6 +288,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> { @@ -288,6 +288,13 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
288 await MobileScannerPlatform.instance.setTorchState(newState); 288 await MobileScannerPlatform.instance.setTorchState(newState);
289 } 289 }
290 290
  291 + /// Update the scan window with the given [window] rectangle.
  292 + ///
  293 + /// If [window] is null, the scan window will be reset to the full camera preview.
  294 + Future<void> updateScanWindow(Rect? window) async {
  295 + await MobileScannerPlatform.instance.updateScanWindow(window);
  296 + }
  297 +
291 @override 298 @override
292 Future<void> dispose() async { 299 Future<void> dispose() async {
293 if (_isDisposed) { 300 if (_isDisposed) {