Quellcode durchsuchen

Add nullcheck and small delay to updateDimensions (#250)

flutter-beta
Julian Steenbakker vor 5 Jahren
Ursprung
Commit
cd8db0f7cc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden GPG-Schlüssel-ID: 16E437C7A3D94250
2 geänderte Dateien mit 21 neuen und 15 gelöschten Zeilen
  1. +4
    -8
      ios/Classes/QRView.swift
  2. +17
    -7
      lib/src/qr_code_scanner.dart

+ 4
- 8
ios/Classes/QRView.swift Datei anzeigen

@@ -32,6 +32,7 @@ public class QRView:NSObject,FlutterPlatformView {
public init(withFrame frame: CGRect, withRegistrar registrar: FlutterPluginRegistrar, withId id: Int64, params: Dictionary<String, Any>){
self.registrar = registrar
previewView = UIView(frame: frame)
scanner = MTBBarcodeScanner(previewView: previewView)
cameraFacing = MTBCamera.init(rawValue: UInt(Int(params["cameraFacing"] as! Double))) ?? MTBCamera.back
channel = FlutterMethodChannel(name: "net.touchcapture.qr.flutterqr/qrview_\(id)", binaryMessenger: registrar.messenger())
}
@@ -97,17 +98,12 @@ public class QRView:NSObject,FlutterPlatformView {
// Then set the size of the scan area.
let midX = self.view().bounds.midX
let midY = self.view().bounds.midY
// Check if the scanner already exists, else create one.
if (self.scanner == nil) {
self.scanner = MTBBarcodeScanner(previewView: self.previewView)
}

// Set the size of the preview.
if let previewLayer = self.scanner?.previewLayer {
previewLayer.frame = self.previewView.bounds;
previewLayer.frame = self.previewView.bounds
}

// Set scanArea if provided.
if (scanArea != 0) {
self.scanner?.didStartScanningBlock = {


+ 17
- 7
lib/src/qr_code_scanner.dart Datei anzeigen

@@ -63,9 +63,13 @@ class _QRViewState extends State<QRView> {
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(LifecycleEventHandler(
resumeCallBack: () async => QRViewController.updateDimensions(
widget.key, _channel,
overlay: widget.overlay)));
resumeCallBack: () async => {
if (_channel != null) {
QRViewController.updateDimensions(
widget.key, _channel,
overlay: widget.overlay)
}
}));
}

@override
@@ -82,9 +86,10 @@ class _QRViewState extends State<QRView> {

bool onNotification(notification) {
Future.microtask(() => {
QRViewController.updateDimensions(widget.key, _channel,
overlay: widget.overlay)
});
QRViewController.updateDimensions(widget.key, _channel,
overlay: widget.overlay)
});

return false;
}

@@ -204,6 +209,7 @@ class QRViewController {

Stream<Barcode> get scannedDataStream => _scanUpdateController.stream;

static bool _firstRun = true;
SystemFeatures _features;
bool _hasPermissions;

@@ -309,8 +315,12 @@ class QRViewController {
static Future<void> updateDimensions(GlobalKey key, MethodChannel channel,
{QrScannerOverlayShape overlay}) async {
if (defaultTargetPlatform == TargetPlatform.iOS) {
if (_firstRun) {
_firstRun = false;
await Future.delayed(Duration(milliseconds: 300));
}
final RenderBox renderBox = key.currentContext.findRenderObject();
try {
try {
await channel.invokeMethod('setDimensions', {
'width': renderBox.size.width,
'height': renderBox.size.height,


Laden…
Abbrechen
Speichern