From d8f5a0eb8260796e5f8c3b97ac0b2abdd8736b2c Mon Sep 17 00:00:00 2001 From: Tihomirov <56314363+OrangeSofter@users.noreply.github.com> Date: Fri, 1 Oct 2021 20:37:07 +0300 Subject: [PATCH] Fixed QrScannerOverlayShape constructor --- lib/src/qr_scanner_overlay_shape.dart | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/src/qr_scanner_overlay_shape.dart b/lib/src/qr_scanner_overlay_shape.dart index 653e3b6..a0a4159 100644 --- a/lib/src/qr_scanner_overlay_shape.dart +++ b/lib/src/qr_scanner_overlay_shape.dart @@ -1,4 +1,5 @@ import 'dart:ui'; +import 'dart:math'; import 'package:flutter/material.dart'; @@ -9,10 +10,20 @@ class QrScannerOverlayShape extends ShapeBorder { this.overlayColor = const Color.fromRGBO(0, 0, 0, 80), this.borderRadius = 0, this.borderLength = 40, - double cutOutSize = 250, + double? cutOutSize, + double? cutOutWidth, + double? cutOutHeight, this.cutOutBottomOffset = 0, - }) : cutOutWidth = cutOutSize, cutOutHeight = cutOutSize, assert(borderLength <= cutOutSize / 2 + borderWidth * 2, - "Border can't be larger than ${cutOutSize / 2 + borderWidth * 2}"); + }): cutOutWidth = cutOutWidth ?? cutOutSize ?? 250, + cutOutHeight = cutOutHeight ?? cutOutSize ?? 250 { + assert( + borderLength <= min(this.cutOutWidth, this.cutOutHeight) / 2 + borderWidth * 2, + "Border can't be larger than ${min(this.cutOutWidth, this.cutOutHeight) / 2 + borderWidth * 2}", + ); + assert((cutOutSize != null && cutOutWidth == null && cutOutHeight == null) || (cutOutSize == null && cutOutWidth != null && cutOutHeight != null), + 'Use only cutOutWidth and cutOutHeight or only cutOutSize' + ); + } final Color borderColor; final double borderWidth;