Showing
5 changed files
with
30 additions
and
25 deletions
| @@ -85,12 +85,8 @@ class _BarcodeScannerReturningImageState | @@ -85,12 +85,8 @@ class _BarcodeScannerReturningImageState | ||
| 85 | child: Row( | 85 | child: Row( |
| 86 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, | 86 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| 87 | children: [ | 87 | children: [ |
| 88 | - ColoredBox( | ||
| 89 | - color: arguments != null && !arguments!.hasTorch | ||
| 90 | - ? Colors.red | ||
| 91 | - : Colors.white, | ||
| 92 | - child: IconButton( | ||
| 93 | - // color: , | 88 | + IconButton( |
| 89 | + color: Colors.white, | ||
| 94 | icon: ValueListenableBuilder( | 90 | icon: ValueListenableBuilder( |
| 95 | valueListenable: controller.torchState, | 91 | valueListenable: controller.torchState, |
| 96 | builder: (context, state, child) { | 92 | builder: (context, state, child) { |
| @@ -117,7 +113,6 @@ class _BarcodeScannerReturningImageState | @@ -117,7 +113,6 @@ class _BarcodeScannerReturningImageState | ||
| 117 | iconSize: 32.0, | 113 | iconSize: 32.0, |
| 118 | onPressed: () => controller.toggleTorch(), | 114 | onPressed: () => controller.toggleTorch(), |
| 119 | ), | 115 | ), |
| 120 | - ), | ||
| 121 | IconButton( | 116 | IconButton( |
| 122 | color: Colors.white, | 117 | color: Colors.white, |
| 123 | icon: isStarted | 118 | icon: isStarted |
| @@ -230,16 +230,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -230,16 +230,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 230 | } | 230 | } |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | - /// Convert image buffer to jpeg | ||
| 234 | - private func ciImageToJpeg(ciImage: CIImage) -> Data { | ||
| 235 | - | ||
| 236 | - // let ciImage = CIImage(cvPixelBuffer: latestBuffer) | ||
| 237 | - let context:CIContext = CIContext.init(options: nil) | ||
| 238 | - let cgImage:CGImage = context.createCGImage(ciImage, from: ciImage.extent)! | ||
| 239 | - let uiImage:UIImage = UIImage(cgImage: cgImage, scale: 1, orientation: UIImage.Orientation.up) | ||
| 240 | - | ||
| 241 | - return uiImage.jpegData(compressionQuality: 0.8)!; | ||
| 242 | - } | 233 | +// /// Convert image buffer to jpeg |
| 234 | +// private func ciImageToJpeg(ciImage: CIImage) -> Data { | ||
| 235 | +// | ||
| 236 | +// // let ciImage = CIImage(cvPixelBuffer: latestBuffer) | ||
| 237 | +// let context:CIContext = CIContext.init(options: nil) | ||
| 238 | +// let cgImage:CGImage = context.createCGImage(ciImage, from: ciImage.extent)! | ||
| 239 | +// let uiImage:UIImage = UIImage(cgImage: cgImage, scale: 1, orientation: UIImage.Orientation.up) | ||
| 240 | +// | ||
| 241 | +// return uiImage.jpegData(compressionQuality: 0.8)!; | ||
| 242 | +// } | ||
| 243 | 243 | ||
| 244 | /// Rotates images accordingly | 244 | /// Rotates images accordingly |
| 245 | func imageOrientation( | 245 | func imageOrientation( |
| @@ -21,7 +21,7 @@ extension CVBuffer { | @@ -21,7 +21,7 @@ extension CVBuffer { | ||
| 21 | var image: UIImage { | 21 | var image: UIImage { |
| 22 | let ciImage = CIImage(cvPixelBuffer: self) | 22 | let ciImage = CIImage(cvPixelBuffer: self) |
| 23 | let cgImage = CIContext().createCGImage(ciImage, from: ciImage.extent) | 23 | let cgImage = CIContext().createCGImage(ciImage, from: ciImage.extent) |
| 24 | - return UIImage(cgImage: cgImage!) | 24 | + return UIImage(cgImage: cgImage!, scale: 1.0, orientation: UIImage.Orientation.left) |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | var image1: UIImage { | 27 | var image1: UIImage { |
| @@ -52,24 +52,30 @@ class _MobileScannerState extends State<MobileScanner> | @@ -52,24 +52,30 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 52 | if (!controller.isStarting) controller.start(); | 52 | if (!controller.isStarting) controller.start(); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | - AppLifecycleState? _lastState; | 55 | + bool resumeFromBackground = false; |
| 56 | 56 | ||
| 57 | @override | 57 | @override |
| 58 | void didChangeAppLifecycleState(AppLifecycleState state) { | 58 | void didChangeAppLifecycleState(AppLifecycleState state) { |
| 59 | + | ||
| 60 | + // App state changed before it is initialized. | ||
| 61 | + if (controller.isStarting) { | ||
| 62 | + return; | ||
| 63 | + } | ||
| 64 | + | ||
| 59 | switch (state) { | 65 | switch (state) { |
| 60 | case AppLifecycleState.resumed: | 66 | case AppLifecycleState.resumed: |
| 61 | - if (!controller.isStarting && | ||
| 62 | - widget.autoResume && | ||
| 63 | - _lastState != AppLifecycleState.inactive) controller.start(); | 67 | + resumeFromBackground = false; |
| 68 | + controller.start(); | ||
| 64 | break; | 69 | break; |
| 65 | case AppLifecycleState.paused: | 70 | case AppLifecycleState.paused: |
| 66 | - case AppLifecycleState.detached: | ||
| 67 | - controller.stop(); | 71 | + resumeFromBackground = true; |
| 72 | + break; | ||
| 73 | + case AppLifecycleState.inactive: | ||
| 74 | + if (!resumeFromBackground) controller.stop(); | ||
| 68 | break; | 75 | break; |
| 69 | default: | 76 | default: |
| 70 | break; | 77 | break; |
| 71 | } | 78 | } |
| 72 | - _lastState = state; | ||
| 73 | } | 79 | } |
| 74 | 80 | ||
| 75 | @override | 81 | @override |
| @@ -202,7 +202,11 @@ class MobileScannerController { | @@ -202,7 +202,11 @@ class MobileScannerController { | ||
| 202 | 202 | ||
| 203 | /// Stops the camera, but does not dispose this controller. | 203 | /// Stops the camera, but does not dispose this controller. |
| 204 | Future<void> stop() async { | 204 | Future<void> stop() async { |
| 205 | + try { | ||
| 205 | await _methodChannel.invokeMethod('stop'); | 206 | await _methodChannel.invokeMethod('stop'); |
| 207 | + } catch (e) { | ||
| 208 | + debugPrint('$e'); | ||
| 209 | + } | ||
| 206 | } | 210 | } |
| 207 | 211 | ||
| 208 | /// Switches the torch on or off. | 212 | /// Switches the torch on or off. |
-
Please register or login to post a comment