| @@ -87,6 +87,17 @@ class QRView(private val registrar: PluginRegistry.Registrar, id: Int) : | |||||
| barcodeView?.resume() | barcodeView?.resume() | ||||
| } | } | ||||
| private fun pauseCamera() { | |||||
| if (barcodeView!!.isPreviewActive) { | |||||
| barcodeView?.pause() | |||||
| } | |||||
| } | |||||
| private fun resumeCamera() { | |||||
| if (!barcodeView!!.isPreviewActive) { | |||||
| barcodeView?.resume() | |||||
| } | |||||
| } | |||||
| override fun getView(): View { | override fun getView(): View { | ||||
| return initBarCodeView()?.apply { | return initBarCodeView()?.apply { | ||||
| @@ -147,6 +158,12 @@ class QRView(private val registrar: PluginRegistry.Registrar, id: Int) : | |||||
| "flipFlash" -> { | "flipFlash" -> { | ||||
| flipFlash() | flipFlash() | ||||
| } | } | ||||
| "pauseCamera" -> { | |||||
| pauseCamera() | |||||
| } | |||||
| "resumeCamera" -> { | |||||
| resumeCamera() | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -85,7 +85,31 @@ class _QRViewExampleState extends State<QRViewExample> { | |||||
| ), | ), | ||||
| ) | ) | ||||
| ], | ], | ||||
| ) | |||||
| ), | |||||
| Row( | |||||
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |||||
| crossAxisAlignment: CrossAxisAlignment.center, | |||||
| children: <Widget>[ | |||||
| 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, | flex: 1, | ||||
| @@ -50,6 +50,10 @@ public class QRView:NSObject,FlutterPlatformView { | |||||
| self?.flipCamera() | self?.flipCamera() | ||||
| case "flipFlash": | case "flipFlash": | ||||
| self?.flipFlash() | self?.flipFlash() | ||||
| case "pauseCamera": | |||||
| self?.pauseCamera() | |||||
| case "resumeCamera": | |||||
| self?.resumeCamera() | |||||
| default: | default: | ||||
| result(FlutterMethodNotImplemented) | result(FlutterMethodNotImplemented) | ||||
| return | return | ||||
| @@ -79,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() | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -83,12 +83,19 @@ class QRViewController { | |||||
| } | } | ||||
| } | } | ||||
| void flipCamera(){ | |||||
| void flipCamera() { | |||||
| channel.invokeMethod("flipCamera"); | channel.invokeMethod("flipCamera"); | ||||
| } | } | ||||
| void flipFlash(){ | |||||
| void flipFlash() { | |||||
| channel.invokeMethod("flipFlash"); | channel.invokeMethod("flipFlash"); | ||||
| } | } | ||||
| void pauseCamera() { | |||||
| channel.invokeMethod("pauseCamera"); | |||||
| } | |||||
| void resumeCamera() { | |||||
| channel.invokeMethod("resumeCamera"); | |||||
| } | |||||
| } | } | ||||