Переглянути джерело

Merge pull request #177 from juliuscanute/125-ipad-rotation

Fixed rotation on iOS.
flutter-beta
Julian Steenbakker 5 роки тому
committed by GitHub
джерело
коміт
d70ded0bb0
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
7 змінених файлів з 71 додано та 40 видалено
  1. +2
    -1
      analysis_options.yaml
  2. +24
    -14
      example/README.md
  3. +24
    -15
      example/lib/main.dart
  4. +1
    -1
      example/pubspec.yaml
  5. +10
    -3
      ios/Classes/QRView.swift
  6. +9
    -5
      lib/src/qr_code_scanner.dart
  7. +1
    -1
      pubspec.yaml

+ 2
- 1
analysis_options.yaml Переглянути файл

@@ -1,4 +1,5 @@
include: package:pedantic/analysis_options.1.9.0.yaml
include: package:pedantic/analysis_options.yaml

linter:
rules:
- always_put_required_named_parameters_first


+ 24
- 14
example/README.md Переглянути файл

@@ -52,20 +52,7 @@ class _QRViewExampleState extends State<QRViewExample> {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
flex: 4,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: 300,
),
),
),
Expanded(flex: 4, child: _buildQrView(context)),
Expanded(
flex: 1,
child: FittedBox(
@@ -163,6 +150,29 @@ class _QRViewExampleState extends State<QRViewExample> {
return backCamera == current;
}

Widget _buildQrView(BuildContext context) {
// To ensure the Scanner view is properly sizes after rotation
// we need to listen for Flutter SizeChanged notification and update controller
return NotificationListener<SizeChangedLayoutNotification>(
onNotification: (notification) {
Future.microtask(() => controller?.updateDimensions(qrKey));
return false;
},
child: SizeChangedLayoutNotifier(
key: const Key('qr-size-notifier'),
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: 300,
),
)));
}

void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {


+ 24
- 15
example/lib/main.dart Переглянути файл

@@ -29,21 +29,7 @@ class _QRViewExampleState extends State<QRViewExample> {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
flex: 4,
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: 300,
cutOutBottomOffset: 24,
),
),
),
Expanded(flex: 4, child: _buildQrView(context)),
Expanded(
flex: 1,
child: FittedBox(
@@ -141,6 +127,29 @@ class _QRViewExampleState extends State<QRViewExample> {
return backCamera == current;
}

Widget _buildQrView(BuildContext context) {
// To ensure the Scanner view is properly sizes after rotation
// we need to listen for Flutter SizeChanged notification and update controller
return NotificationListener<SizeChangedLayoutNotification>(
onNotification: (notification) {
Future.microtask(() => controller?.updateDimensions(qrKey));
return false;
},
child: SizeChangedLayoutNotifier(
key: const Key('qr-size-notifier'),
child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Colors.red,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: 300,
),
)));
}

void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) {


+ 1
- 1
example/pubspec.yaml Переглянути файл

@@ -3,7 +3,7 @@ description: Demonstrates how to use the flutter_qr plugin.
publish_to: 'none'

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.3.0 <3.0.0"

dependencies:
flutter:


+ 10
- 3
ios/Classes/QRView.swift Переглянути файл

@@ -63,9 +63,16 @@ public class QRView:NSObject,FlutterPlatformView {
}
func setDimensions(width: Double, height: Double) -> Void {
previewView.frame = CGRect(x: 0, y: 0, width: width, height: height)
scanner = MTBBarcodeScanner(previewView: previewView)
MTBBarcodeScanner.requestCameraPermission(success: isCameraAvailable)
previewView.frame = CGRect(x: 0, y: 0, width: width, height: height)

if let sc: MTBBarcodeScanner = scanner {
if let previewLayer = sc.previewLayer {
previewLayer.frame = previewView.bounds;
}
} else {
scanner = MTBBarcodeScanner(previewView: previewView)
MTBBarcodeScanner.requestCameraPermission(success: isCameraAvailable)
}
}
func flipCamera(){


+ 9
- 5
lib/src/qr_code_scanner.dart Переглянути файл

@@ -100,11 +100,7 @@ class _CreationParams {
class QRViewController {
QRViewController._(int id, GlobalKey qrKey)
: _channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id') {
if (defaultTargetPlatform == TargetPlatform.iOS) {
final RenderBox renderBox = qrKey.currentContext.findRenderObject();
_channel.invokeMethod('setDimensions',
{'width': renderBox.size.width, 'height': renderBox.size.height});
}
updateDimensions(qrKey);
_channel.setMethodCallHandler(
(call) async {
switch (call.method) {
@@ -145,4 +141,12 @@ class QRViewController {
void dispose() {
_scanUpdateController.close();
}

void updateDimensions(GlobalKey key) {
if (defaultTargetPlatform == TargetPlatform.iOS) {
final RenderBox renderBox = key.currentContext.findRenderObject();
_channel.invokeMethod('setDimensions',
{'width': renderBox.size.width, 'height': renderBox.size.height});
}
}
}

+ 1
- 1
pubspec.yaml Переглянути файл

@@ -14,7 +14,7 @@ dependencies:
sdk: flutter

dev_dependencies:
pedantic: ^1.9.0
pedantic: ^1.9.2

flutter:
plugin:


Завантаження…
Відмінити
Зберегти