ソースを参照

Merge pull request #244 from juliuscanute/235-bottom-offset

235 bottom offset
flutter-beta
Julian Steenbakker 5年前
committed by GitHub
コミット
7e2d7172c4
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4AEE18F83AFDEB23
3個のファイルの変更27行の追加21行の削除
  1. +1
    -2
      example/android/gradle.properties
  2. +16
    -2
      ios/Classes/QRView.swift
  3. +10
    -17
      lib/src/qr_code_scanner.dart

+ 1
- 2
example/android/gradle.properties ファイルの表示

@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
android.enableJetifier=true

+ 16
- 2
ios/Classes/QRView.swift ファイルの表示

@@ -46,7 +46,11 @@ public class QRView:NSObject,FlutterPlatformView {
switch(call.method){
case "setDimensions":
let arguments = call.arguments as! Dictionary<String, Double>
self?.setDimensions(result, width: arguments["width"] ?? 0, height: arguments["height"] ?? 0, scanArea: arguments["scanArea"] ?? 0)
self?.setDimensions(result,
width: arguments["width"] ?? 0,
height: arguments["height"] ?? 0,
scanArea: arguments["scanArea"] ?? 0,
scanAreaOffset: arguments["scanAreaOffset"] ?? 0)
case "startScan":
self?.startScan(call.arguments as! Array<Int>, result)
case "flipCamera":
@@ -71,7 +75,7 @@ public class QRView:NSObject,FlutterPlatformView {
return previewView
}
func setDimensions(_ result: @escaping FlutterResult, width: Double, height: Double, scanArea: Double) -> Void {
func setDimensions(_ result: @escaping FlutterResult, width: Double, height: Double, scanArea: Double, scanAreaOffset: Double) -> Void {
MTBBarcodeScanner.requestCameraPermission(success: { permissionGranted in
if permissionGranted {
// self?.channel.invokeMethod("onPermissionSet", arguments: true)
@@ -89,6 +93,11 @@ public class QRView:NSObject,FlutterPlatformView {
}
if (scanArea != 0) {
sc.scanRect = CGRect(x: Double(midX) - (scanArea / 2), y: Double(midY) - (scanArea / 2), width: scanArea, height: scanArea)
// Set offset if provided.
if (scanAreaOffset != 0) {
sc.scanRect = sc.scanRect.offsetBy(dx: 0, dy: CGFloat(scanAreaOffset))
}
}
} else {
// Create a scanner view if it doesn't exist yet.
@@ -97,6 +106,11 @@ public class QRView:NSObject,FlutterPlatformView {
if (scanArea != 0) {
self.scanner?.didStartScanningBlock = {
self.scanner?.scanRect = CGRect(x: Double(midX) - (scanArea / 2), y: Double(midY) - (scanArea / 2), width: scanArea, height: scanArea)
// Set offset if provided.
if (scanAreaOffset != 0) {
self.scanner?.scanRect = (self.scanner?.scanRect.offsetBy(dx: 0, dy: CGFloat(scanAreaOffset)))!
}
}
}
}


+ 10
- 17
lib/src/qr_code_scanner.dart ファイルの表示

@@ -73,8 +73,7 @@ class _QRViewState extends State<QRView> {
bool onNotification(notification) {
Future.microtask(() => {
QRViewController.updateDimensions(widget.key, _channel,
scanArea:
widget.overlay != null ? widget.overlay.cutOutSize : 0.0)
overlay: widget.overlay)
});
return false;
}
@@ -122,18 +121,12 @@ class _QRViewState extends State<QRView> {
}

void _onPlatformViewCreated(int id) {
// We pass the cutout size so that the scanner respects the scan area.
var cutOutSize = 0.0;
if (widget.overlay != null) {
cutOutSize = widget.overlay.cutOutSize;
}

_channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id');

// Start scan after creation of the view
final controller = QRViewController._(
_channel, widget.key, cutOutSize, widget.onPermissionSet)
.._startScan(widget.key, cutOutSize, widget.formatsAllowed);
final controller =
QRViewController._(_channel, widget.key, widget.onPermissionSet)
.._startScan(widget.key, widget.overlay, widget.formatsAllowed);

// Initialize the controller for controlling the QRView
if (widget.onQRViewCreated != null) {
@@ -157,7 +150,7 @@ class _QrCameraSettings {
}

class QRViewController {
QRViewController._(MethodChannel channel, GlobalKey qrKey, double scanArea,
QRViewController._(MethodChannel channel, GlobalKey qrKey,
PermissionSetCallback onPermissionSet)
: _channel = channel {
_channel.setMethodCallHandler((call) async {
@@ -208,12 +201,11 @@ class QRViewController {
bool get hasPermissions => _hasPermissions;

/// Starts the barcode scanner
Future<void> _startScan(GlobalKey key, double cutOutSize,
Future<void> _startScan(GlobalKey key, QrScannerOverlayShape overlay,
List<BarcodeFormat> barcodeFormats) async {
// We need to update the dimension before the scan is started.
try {
await QRViewController.updateDimensions(key, _channel,
scanArea: cutOutSize);
await QRViewController.updateDimensions(key, _channel, overlay: overlay);
return await _channel.invokeMethod(
'startScan', barcodeFormats?.map((e) => e.asInt())?.toList() ?? []);
} on PlatformException catch (e) {
@@ -295,14 +287,15 @@ class QRViewController {

/// Updates the view dimensions for iOS.
static Future<void> updateDimensions(GlobalKey key, MethodChannel channel,
{double scanArea}) async {
{QrScannerOverlayShape overlay}) async {
if (defaultTargetPlatform == TargetPlatform.iOS) {
final RenderBox renderBox = key.currentContext.findRenderObject();
try {
await channel.invokeMethod('setDimensions', {
'width': renderBox.size.width,
'height': renderBox.size.height,
'scanArea': scanArea ?? 0
'scanArea': overlay.cutOutSize ?? 0,
'scanAreaOffset': overlay.cutOutBottomOffset ?? 0
});
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);


読み込み中…
キャンセル
保存