updateDimensions static method

Future<bool> updateDimensions(
  1. GlobalKey<State<StatefulWidget>> key,
  2. MethodChannel channel, {
  3. QrScannerOverlayShape? overlay,
})

Updates the view dimensions for iOS.

Implementation

static Future<bool> updateDimensions(GlobalKey key, MethodChannel channel,
    {QrScannerOverlayShape? overlay}) async {
  if (defaultTargetPlatform == TargetPlatform.iOS) {
    // Add small delay to ensure the render box is loaded
    await Future.delayed(const Duration(milliseconds: 300));
    if (key.currentContext == null) return false;
    final renderBox = key.currentContext!.findRenderObject() as RenderBox;
    try {
      await channel.invokeMethod('setDimensions', {
        'width': renderBox.size.width,
        'height': renderBox.size.height,
        'scanAreaWidth': overlay?.cutOutWidth ?? 0,
        'scanAreaHeight': overlay?.cutOutHeight ?? 0,
        'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0
      });
      return true;
    } on PlatformException catch (e) {
      throw CameraException(e.code, e.message);
    }
  } else if (defaultTargetPlatform == TargetPlatform.android) {
    if (overlay == null) {
      return false;
    }
    await channel.invokeMethod('changeScanArea', {
      'scanAreaWidth': overlay.cutOutWidth,
      'scanAreaHeight': overlay.cutOutHeight,
      'cutOutBottomOffset': overlay.cutOutBottomOffset
    });
    return true;
  }
  return false;
}