diff --git a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt index 4722d91..d99ddfb 100644 --- a/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt +++ b/android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt @@ -89,6 +89,17 @@ class QRView(private val registrar: PluginRegistry.Registrar, id: Int) : } + private fun pauseCamera() { + if (barcodeView!!.isPreviewActive) { + barcodeView?.pause() + } + } + + private fun resumeCamera() { + if (!barcodeView!!.isPreviewActive) { + barcodeView?.resume() + } + } private fun hasFlash(): Boolean { return registrar.activeContext().packageManager @@ -154,6 +165,12 @@ class QRView(private val registrar: PluginRegistry.Registrar, id: Int) : "toggleFlash" -> { toggleFlash() } + "pauseCamera" -> { + pauseCamera() + } + "resumeCamera" -> { + resumeCamera() + } } } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cc84123..c345c14 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -17,19 +17,19 @@ pool: steps: - script: | cd example - $(flutterPath)/flutter build ios + $flutterPath/flutter build ios displayName: 'Test iOS -- Build' env: flutterPath: $(flutterPath) - script: | cd example - $(flutterPath)/flutter packages get - $(flutterPath)/flutter build apk --target-platform android-arm,android-arm64 --split-per-abi + $flutterPath/flutter packages get + $flutterPath/flutter build apk --target-platform android-arm,android-arm64 --split-per-abi displayName: 'Test Android -- Build' env: flutterPath: $(flutterPath) - script: | - $(flutterPath)/flutter pub pub publish --dry-run + $flutterPath/flutter pub pub publish --dry-run displayName: 'Publish -- Dry Run' env: flutterPath: $(flutterPath) \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 6f15e7f..cc85f8a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -85,7 +85,31 @@ class _QRViewExampleState extends State { ), ) ], - ) + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + margin: EdgeInsets.only(bottom: 8.0), + child: RaisedButton( + onPressed: () { + controller?.pauseCamera(); + }, + child: Text('pause', style: TextStyle(fontSize: 20)), + ), + ), + Container( + margin: EdgeInsets.only(bottom: 8.0), + child: RaisedButton( + onPressed: () { + controller.resumeCamera(); + }, + child: Text('resume', style: TextStyle(fontSize: 20)), + ), + ) + ], + ), ], ), flex: 1, diff --git a/ios/Classes/QRView.swift b/ios/Classes/QRView.swift index a83841d..4a4ee34 100644 --- a/ios/Classes/QRView.swift +++ b/ios/Classes/QRView.swift @@ -83,4 +83,20 @@ public class QRView:NSObject,FlutterPlatformView { } } } + + func pauseCamera() { + if let sc: MTBBarcodeScanner = scanner { + if sc.isScanning() { + sc.freezeCapture() + } + } + } + + func resumeCamera() { + if let sc: MTBBarcodeScanner = scanner { + if !sc.isScanning() { + sc.unfreezeCapture() + } + } + } } diff --git a/lib/qr_code_scanner.dart b/lib/qr_code_scanner.dart index 0b0415f..2f1cde2 100644 --- a/lib/qr_code_scanner.dart +++ b/lib/qr_code_scanner.dart @@ -90,4 +90,12 @@ class QRViewController { void toggleFlash() { channel.invokeMethod("toggleFlash"); } + + void pauseCamera() { + channel.invokeMethod("pauseCamera"); + } + + void resumeCamera() { + channel.invokeMethod("resumeCamera"); + } }