Explorar el Código

Added methods for pausing/resuming camera

flutter-beta
Luis Thein hace 7 años
padre
commit
ddd55e18a1
Se han modificado 4 ficheros con 71 adiciones y 3 borrados
  1. +17
    -0
      android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt
  2. +25
    -1
      example/lib/main.dart
  3. +20
    -0
      ios/Classes/QRView.swift
  4. +9
    -2
      lib/qr_code_scanner.dart

+ 17
- 0
android/src/main/kotlin/net/touchcapture/qr/flutterqr/QRView.kt Ver fichero

@@ -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()
}
} }
} }




+ 25
- 1
example/lib/main.dart Ver fichero

@@ -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,


+ 20
- 0
ios/Classes/QRView.swift Ver fichero

@@ -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()
}
}
}
} }

+ 9
- 2
lib/qr_code_scanner.dart Ver fichero

@@ -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");
}
} }

Cargando…
Cancelar
Guardar