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

Merge pull request #26 from LuisThein/feature/pauseResumeCamera

Add ability to pause/resume the camera
flutter-beta
juliuscanute 7 роки тому
committed by GitHub
джерело
коміт
a223a7d5cd
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
4 змінених файлів з 71 додано та 3 видалено
  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 Переглянути файл

@@ -87,6 +87,17 @@ class QRView(private val registrar: PluginRegistry.Registrar, id: Int) :
barcodeView?.resume()
}

private fun pauseCamera() {
if (barcodeView!!.isPreviewActive) {
barcodeView?.pause()
}
}

private fun resumeCamera() {
if (!barcodeView!!.isPreviewActive) {
barcodeView?.resume()
}
}

override fun getView(): View {
return initBarCodeView()?.apply {
@@ -147,6 +158,12 @@ class QRView(private val registrar: PluginRegistry.Registrar, id: Int) :
"flipFlash" -> {
flipFlash()
}
"pauseCamera" -> {
pauseCamera()
}
"resumeCamera" -> {
resumeCamera()
}
}
}



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

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


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

@@ -50,6 +50,10 @@ public class QRView:NSObject,FlutterPlatformView {
self?.flipCamera()
case "flipFlash":
self?.flipFlash()
case "pauseCamera":
self?.pauseCamera()
case "resumeCamera":
self?.resumeCamera()
default:
result(FlutterMethodNotImplemented)
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 Переглянути файл

@@ -83,12 +83,19 @@ class QRViewController {
}
}

void flipCamera(){
void flipCamera() {
channel.invokeMethod("flipCamera");
}

void flipFlash(){
void flipFlash() {
channel.invokeMethod("flipFlash");
}

void pauseCamera() {
channel.invokeMethod("pauseCamera");
}

void resumeCamera() {
channel.invokeMethod("resumeCamera");
}
}

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