Преглед изворни кода

Merge branch 'master' into gradle-upgrade

flutter-beta
Julian Steenbakker пре 4 година
committed by GitHub
родитељ
комит
ceb5619d67
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 измењених фајлова са 47 додато и 24 уклоњено
  1. +3
    -3
      android/build.gradle
  2. +5
    -3
      android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt
  3. +5
    -4
      ios/Classes/QRView.swift
  4. +4
    -2
      lib/src/qr_code_scanner.dart
  5. +30
    -12
      lib/src/qr_scanner_overlay_shape.dart

+ 3
- 3
android/build.gradle Прегледај датотеку

@@ -48,8 +48,8 @@ android {


dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.zxing:core:3.4.1'
implementation('com.journeyapps:zxing-android-embedded:4.2.0') { transitive = false }
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.zxing:core:3.3.3'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
} }

+ 5
- 3
android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt Прегледај датотеку

@@ -85,7 +85,8 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
"getFlashInfo" -> getFlashInfo(result) "getFlashInfo" -> getFlashInfo(result)
"getSystemFeatures" -> getSystemFeatures(result) "getSystemFeatures" -> getSystemFeatures(result)
"changeScanArea" -> changeScanArea( "changeScanArea" -> changeScanArea(
call.argument<Double>("cutOutSize")!!,
call.argument<Double>("scanAreaWidth")!!,
call.argument<Double>("scanAreaHeight")!!,
call.argument<Double>("cutOutBottomOffset")!!, call.argument<Double>("cutOutBottomOffset")!!,
result, result,
) )
@@ -249,11 +250,12 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v
} }


private fun changeScanArea( private fun changeScanArea(
cutOutSize: Double,
dpScanAreaWidth: Double,
dpScanAreaHeight: Double,
cutOutBottomOffset: Double, cutOutBottomOffset: Double,
result: MethodChannel.Result result: MethodChannel.Result
) { ) {
setScanAreaSize(cutOutSize, cutOutSize, cutOutBottomOffset)
setScanAreaSize(dpScanAreaWidth, dpScanAreaHeight, cutOutBottomOffset)
result.success(true) result.success(true)
} }




+ 5
- 4
ios/Classes/QRView.swift Прегледај датотеку

@@ -56,7 +56,8 @@ public class QRView:NSObject,FlutterPlatformView {
self?.setDimensions(result, self?.setDimensions(result,
width: arguments["width"] ?? 0, width: arguments["width"] ?? 0,
height: arguments["height"] ?? 0, height: arguments["height"] ?? 0,
scanArea: arguments["scanArea"] ?? 0,
scanAreaWidth: arguments["scanAreaWidth"] ?? 0,
scanAreaHeight: arguments["scanAreaHeight"] ?? 0,
scanAreaOffset: arguments["scanAreaOffset"] ?? 0) scanAreaOffset: arguments["scanAreaOffset"] ?? 0)
case "startScan": case "startScan":
self?.startScan(call.arguments as! Array<Int>, result) self?.startScan(call.arguments as! Array<Int>, result)
@@ -84,7 +85,7 @@ public class QRView:NSObject,FlutterPlatformView {
return previewView return previewView
} }
func setDimensions(_ result: @escaping FlutterResult, width: Double, height: Double, scanArea: Double, scanAreaOffset: Double) {
func setDimensions(_ result: @escaping FlutterResult, width: Double, height: Double, scanAreaWidth: Double, scanAreaHeight: Double, scanAreaOffset: Double) {
// Then set the size of the preview area. // Then set the size of the preview area.
previewView.frame = CGRect(x: 0, y: 0, width: width, height: height) previewView.frame = CGRect(x: 0, y: 0, width: width, height: height)
@@ -103,9 +104,9 @@ public class QRView:NSObject,FlutterPlatformView {
} }


// Set scanArea if provided. // Set scanArea if provided.
if (scanArea != 0) {
if (scanAreaWidth != 0 && scanAreaHeight != 0) {
scanner?.didStartScanningBlock = { scanner?.didStartScanningBlock = {
self.scanner?.scanRect = CGRect(x: Double(midX) - (scanArea / 2), y: Double(midY) - (scanArea / 2), width: scanArea, height: scanArea)
self.scanner?.scanRect = CGRect(x: Double(midX) - (scanAreaWidth / 2), y: Double(midY) - (scanAreaHeight / 2), width: scanAreaWidth, height: scanAreaHeight)


// Set offset if provided. // Set offset if provided.
if (scanAreaOffset != 0) { if (scanAreaOffset != 0) {


+ 4
- 2
lib/src/qr_code_scanner.dart Прегледај датотеку

@@ -334,7 +334,8 @@ class QRViewController {
await channel.invokeMethod('setDimensions', { await channel.invokeMethod('setDimensions', {
'width': renderBox.size.width, 'width': renderBox.size.width,
'height': renderBox.size.height, 'height': renderBox.size.height,
'scanArea': overlay?.cutOutSize ?? 0,
'scanAreaWidth': overlay?.cutOutWidth ?? 0,
'scanAreaHeight': overlay?.cutOutHeight ?? 0,
'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0 'scanAreaOffset': overlay?.cutOutBottomOffset ?? 0
}); });
return true; return true;
@@ -346,7 +347,8 @@ class QRViewController {
return false; return false;
} }
await channel.invokeMethod('changeScanArea', { await channel.invokeMethod('changeScanArea', {
'cutOutSize': overlay.cutOutSize,
'scanAreaWidth': overlay.cutOutWidth,
'scanAreaHeight': overlay.cutOutHeight,
'cutOutBottomOffset': overlay.cutOutBottomOffset 'cutOutBottomOffset': overlay.cutOutBottomOffset
}); });
return true; return true;


+ 30
- 12
lib/src/qr_scanner_overlay_shape.dart Прегледај датотеку

@@ -1,4 +1,5 @@
import 'dart:ui'; import 'dart:ui';
import 'dart:math';


import 'package:flutter/material.dart'; import 'package:flutter/material.dart';


@@ -9,17 +10,30 @@ class QrScannerOverlayShape extends ShapeBorder {
this.overlayColor = const Color.fromRGBO(0, 0, 0, 80), this.overlayColor = const Color.fromRGBO(0, 0, 0, 80),
this.borderRadius = 0, this.borderRadius = 0,
this.borderLength = 40, this.borderLength = 40,
this.cutOutSize = 250,
double? cutOutSize,
double? cutOutWidth,
double? cutOutHeight,
this.cutOutBottomOffset = 0, this.cutOutBottomOffset = 0,
}) : 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 Color borderColor;
final double borderWidth; final double borderWidth;
final Color overlayColor; final Color overlayColor;
final double borderRadius; final double borderRadius;
final double borderLength; final double borderLength;
final double cutOutSize;
final double cutOutWidth;
final double cutOutHeight;
final double cutOutBottomOffset; final double cutOutBottomOffset;


@override @override
@@ -62,10 +76,14 @@ class QrScannerOverlayShape extends ShapeBorder {
final borderWidthSize = width / 2; final borderWidthSize = width / 2;
final height = rect.height; final height = rect.height;
final borderOffset = borderWidth / 2; final borderOffset = borderWidth / 2;
final _borderLength = borderLength > cutOutSize / 2 + borderWidth * 2
? borderWidthSize / 2
: borderLength;
final _cutOutSize = cutOutSize < width ? cutOutSize : width - borderOffset;
final _borderLength =
borderLength > min(cutOutHeight, cutOutHeight) / 2 + borderWidth * 2
? borderWidthSize / 2
: borderLength;
final _cutOutWidth =
cutOutWidth < width ? cutOutWidth : width - borderOffset;
final _cutOutHeight =
cutOutHeight < height ? cutOutHeight : height - borderOffset;


final backgroundPaint = Paint() final backgroundPaint = Paint()
..color = overlayColor ..color = overlayColor
@@ -82,14 +100,14 @@ class QrScannerOverlayShape extends ShapeBorder {
..blendMode = BlendMode.dstOut; ..blendMode = BlendMode.dstOut;


final cutOutRect = Rect.fromLTWH( final cutOutRect = Rect.fromLTWH(
rect.left + width / 2 - _cutOutSize / 2 + borderOffset,
rect.left + width / 2 - _cutOutWidth / 2 + borderOffset,
-cutOutBottomOffset + -cutOutBottomOffset +
rect.top + rect.top +
height / 2 - height / 2 -
_cutOutSize / 2 +
_cutOutHeight / 2 +
borderOffset, borderOffset,
_cutOutSize - borderOffset * 2,
_cutOutSize - borderOffset * 2,
_cutOutWidth - borderOffset * 2,
_cutOutHeight - borderOffset * 2,
); );


canvas canvas


Loading…
Откажи
Сачувај