Merge branch 'master' into dependabot/gradle/android/com.android.tools.build-gradle-7.1.1
Showing
11 changed files
with
166 additions
and
144 deletions
| 1 | -import 'dart:ui'; | ||
| 2 | - | ||
| 3 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 4 | import 'package:mobile_scanner/mobile_scanner.dart'; | 2 | import 'package:mobile_scanner/mobile_scanner.dart'; |
| 5 | 3 | ||
| @@ -18,8 +16,10 @@ class _AnalyzeViewState extends State<AnalyzeView> | @@ -18,8 +16,10 @@ class _AnalyzeViewState extends State<AnalyzeView> | ||
| 18 | with SingleTickerProviderStateMixin { | 16 | with SingleTickerProviderStateMixin { |
| 19 | String? barcode; | 17 | String? barcode; |
| 20 | 18 | ||
| 21 | - MobileScannerController controller = MobileScannerController(torchEnabled: true, | ||
| 22 | - facing: CameraFacing.front,); | 19 | + MobileScannerController controller = MobileScannerController( |
| 20 | + torchEnabled: true, | ||
| 21 | + facing: CameraFacing.front, | ||
| 22 | + ); | ||
| 23 | 23 | ||
| 24 | @override | 24 | @override |
| 25 | Widget build(BuildContext context) { | 25 | Widget build(BuildContext context) { |
| @@ -30,7 +30,7 @@ class _AnalyzeViewState extends State<AnalyzeView> | @@ -30,7 +30,7 @@ class _AnalyzeViewState extends State<AnalyzeView> | ||
| 30 | return Stack( | 30 | return Stack( |
| 31 | children: [ | 31 | children: [ |
| 32 | MobileScanner( | 32 | MobileScanner( |
| 33 | - controller: controller, | 33 | + controller: controller, |
| 34 | fit: BoxFit.contain, | 34 | fit: BoxFit.contain, |
| 35 | // controller: MobileScannerController( | 35 | // controller: MobileScannerController( |
| 36 | // torchEnabled: true, | 36 | // torchEnabled: true, |
| @@ -55,20 +55,22 @@ class _AnalyzeViewState extends State<AnalyzeView> | @@ -55,20 +55,22 @@ class _AnalyzeViewState extends State<AnalyzeView> | ||
| 55 | children: [ | 55 | children: [ |
| 56 | IconButton( | 56 | IconButton( |
| 57 | color: Colors.white, | 57 | color: Colors.white, |
| 58 | - icon: ValueListenableBuilder( | ||
| 59 | - valueListenable: controller.torchState, | ||
| 60 | - builder: (context, state, child) { | ||
| 61 | - switch (state as TorchState) { | ||
| 62 | - case TorchState.off: | ||
| 63 | - return const Icon(Icons.flash_off, color: Colors.grey); | ||
| 64 | - case TorchState.on: | ||
| 65 | - return const Icon(Icons.flash_on, color: Colors.yellow); | ||
| 66 | - } | ||
| 67 | - }, | ||
| 68 | - ), | ||
| 69 | - iconSize: 32.0, | ||
| 70 | - onPressed: () => controller.toggleTorch(), | 58 | + icon: ValueListenableBuilder( |
| 59 | + valueListenable: controller.torchState, | ||
| 60 | + builder: (context, state, child) { | ||
| 61 | + switch (state as TorchState) { | ||
| 62 | + case TorchState.off: | ||
| 63 | + return const Icon(Icons.flash_off, | ||
| 64 | + color: Colors.grey); | ||
| 65 | + case TorchState.on: | ||
| 66 | + return const Icon(Icons.flash_on, | ||
| 67 | + color: Colors.yellow); | ||
| 68 | + } | ||
| 69 | + }, | ||
| 71 | ), | 70 | ), |
| 71 | + iconSize: 32.0, | ||
| 72 | + onPressed: () => controller.toggleTorch(), | ||
| 73 | + ), | ||
| 72 | Center( | 74 | Center( |
| 73 | child: SizedBox( | 75 | child: SizedBox( |
| 74 | width: MediaQuery.of(context).size.width - 120, | 76 | width: MediaQuery.of(context).size.width - 120, |
| @@ -20,7 +20,7 @@ class _AnalyzeViewState extends State<AnalyzeView> | @@ -20,7 +20,7 @@ class _AnalyzeViewState extends State<AnalyzeView> | ||
| 20 | 20 | ||
| 21 | // CameraController cameraController = CameraController(context, width: 320, height: 150); | 21 | // CameraController cameraController = CameraController(context, width: 320, height: 150); |
| 22 | 22 | ||
| 23 | - String? barcode = null; | 23 | + String? barcode; |
| 24 | 24 | ||
| 25 | @override | 25 | @override |
| 26 | Widget build(BuildContext context) { | 26 | Widget build(BuildContext context) { |
| @@ -30,40 +30,41 @@ class _AnalyzeViewState extends State<AnalyzeView> | @@ -30,40 +30,41 @@ class _AnalyzeViewState extends State<AnalyzeView> | ||
| 30 | return Stack( | 30 | return Stack( |
| 31 | children: [ | 31 | children: [ |
| 32 | MobileScanner( | 32 | MobileScanner( |
| 33 | - // fitScreen: false, | 33 | + // fitScreen: false, |
| 34 | // controller: cameraController, | 34 | // controller: cameraController, |
| 35 | onDetect: (barcode, args) { | 35 | onDetect: (barcode, args) { |
| 36 | - if (this.barcode != barcode.rawValue) { | ||
| 37 | - this.barcode = barcode.rawValue; | ||
| 38 | - if (barcode.corners != null) { | ||
| 39 | - ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||
| 40 | - content: Text('${barcode.rawValue}'), | ||
| 41 | - duration: const Duration(milliseconds: 200), | ||
| 42 | - animation: null, | ||
| 43 | - )); | ||
| 44 | - setState(() { | ||
| 45 | - final List<Offset> points = []; | ||
| 46 | - double factorWidth = args.size.width / 520; | ||
| 47 | - // double factorHeight = wanted / args.size.height; | ||
| 48 | - final size = MediaQuery.of(context).devicePixelRatio; | ||
| 49 | - debugPrint('Size: ${barcode.corners}'); | ||
| 50 | - for (var point in barcode.corners!) { | ||
| 51 | - final adjustedWith = point.dx ; | ||
| 52 | - final adjustedHeight= point.dy ; | ||
| 53 | - points.add(Offset(adjustedWith / size, adjustedHeight / size)); | ||
| 54 | - // points.add(Offset((point.dx ) / size, | ||
| 55 | - // (point.dy) / size)); | ||
| 56 | - // final differenceWidth = (args.wantedSize!.width - args.size.width) / 2; | ||
| 57 | - // final differenceHeight = (args.wantedSize!.height - args.size.height) / 2; | ||
| 58 | - // points.add(Offset((point.dx + differenceWidth) / size, | ||
| 59 | - // (point.dy + differenceHeight) / size)); | ||
| 60 | - } | ||
| 61 | - this.points = points; | ||
| 62 | - }); | 36 | + if (this.barcode != barcode.rawValue) { |
| 37 | + this.barcode = barcode.rawValue; | ||
| 38 | + if (barcode.corners != null) { | ||
| 39 | + ScaffoldMessenger.of(context).showSnackBar(SnackBar( | ||
| 40 | + content: Text(barcode.rawValue), | ||
| 41 | + duration: const Duration(milliseconds: 200), | ||
| 42 | + animation: null, | ||
| 43 | + )); | ||
| 44 | + setState(() { | ||
| 45 | + final List<Offset> points = []; | ||
| 46 | + // double factorWidth = args.size.width / 520; | ||
| 47 | + // double factorHeight = wanted / args.size.height; | ||
| 48 | + final size = MediaQuery.of(context).devicePixelRatio; | ||
| 49 | + debugPrint('Size: ${barcode.corners}'); | ||
| 50 | + for (var point in barcode.corners!) { | ||
| 51 | + final adjustedWith = point.dx; | ||
| 52 | + final adjustedHeight = point.dy; | ||
| 53 | + points.add( | ||
| 54 | + Offset(adjustedWith / size, adjustedHeight / size)); | ||
| 55 | + // points.add(Offset((point.dx ) / size, | ||
| 56 | + // (point.dy) / size)); | ||
| 57 | + // final differenceWidth = (args.wantedSize!.width - args.size.width) / 2; | ||
| 58 | + // final differenceHeight = (args.wantedSize!.height - args.size.height) / 2; | ||
| 59 | + // points.add(Offset((point.dx + differenceWidth) / size, | ||
| 60 | + // (point.dy + differenceHeight) / size)); | ||
| 63 | } | 61 | } |
| 64 | - } | ||
| 65 | - // Default 640 x480 | ||
| 66 | - }), | 62 | + this.points = points; |
| 63 | + }); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + // Default 640 x480 | ||
| 67 | + }), | ||
| 67 | CustomPaint( | 68 | CustomPaint( |
| 68 | painter: OpenPainter(points), | 69 | painter: OpenPainter(points), |
| 69 | ), | 70 | ), |
| @@ -108,7 +109,7 @@ class OpenPainter extends CustomPainter { | @@ -108,7 +109,7 @@ class OpenPainter extends CustomPainter { | ||
| 108 | @override | 109 | @override |
| 109 | void paint(Canvas canvas, Size size) { | 110 | void paint(Canvas canvas, Size size) { |
| 110 | var paint1 = Paint() | 111 | var paint1 = Paint() |
| 111 | - ..color = Color(0xff63aa65) | 112 | + ..color = const Color(0xff63aa65) |
| 112 | ..strokeWidth = 10; | 113 | ..strokeWidth = 10; |
| 113 | //draw points on canvas | 114 | //draw points on canvas |
| 114 | canvas.drawPoints(PointMode.points, points, paint1); | 115 | canvas.drawPoints(PointMode.points, points, paint1); |
| @@ -5,11 +5,8 @@ | @@ -5,11 +5,8 @@ | ||
| 5 | // gestures. You can also use WidgetTester to find child widgets in the widget | 5 | // gestures. You can also use WidgetTester to find child widgets in the widget |
| 6 | // tree, read text, and verify that the values of widget properties are correct. | 6 | // tree, read text, and verify that the values of widget properties are correct. |
| 7 | 7 | ||
| 8 | -import 'package:flutter/material.dart'; | ||
| 9 | import 'package:flutter_test/flutter_test.dart'; | 8 | import 'package:flutter_test/flutter_test.dart'; |
| 10 | 9 | ||
| 11 | -import 'package:mobile_scanner_example/main.dart'; | ||
| 12 | - | ||
| 13 | void main() { | 10 | void main() { |
| 14 | testWidgets('Verify Platform version', (WidgetTester tester) async { | 11 | testWidgets('Verify Platform version', (WidgetTester tester) async { |
| 15 | // Build our app and trigger a frame. | 12 | // Build our app and trigger a frame. |
| @@ -53,11 +53,11 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -53,11 +53,11 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 53 | case "start": | 53 | case "start": |
| 54 | start(call, result) | 54 | start(call, result) |
| 55 | case "torch": | 55 | case "torch": |
| 56 | - torchNative(call, result) | 56 | + switchTorch(call, result) |
| 57 | case "analyze": | 57 | case "analyze": |
| 58 | - analyzeNative(call, result) | 58 | + switchAnalyzeMode(call, result) |
| 59 | case "stop": | 59 | case "stop": |
| 60 | - stopNative(result) | 60 | + stop(result) |
| 61 | default: | 61 | default: |
| 62 | result(FlutterMethodNotImplemented) | 62 | result(FlutterMethodNotImplemented) |
| 63 | } | 63 | } |
| @@ -83,58 +83,59 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -83,58 +83,59 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 83 | return Unmanaged<CVPixelBuffer>.passRetained(latestBuffer) | 83 | return Unmanaged<CVPixelBuffer>.passRetained(latestBuffer) |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | -// public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | ||
| 87 | -// | ||
| 88 | -// latestBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) | ||
| 89 | -// registry.textureFrameAvailable(textureId) | ||
| 90 | -// | ||
| 91 | -// switch analyzeMode { | ||
| 92 | -// case 1: // barcode | ||
| 93 | -// if analyzing { | ||
| 94 | -// break | ||
| 95 | -// } | ||
| 96 | -// analyzing = true | ||
| 97 | -// let buffer = CMSampleBufferGetImageBuffer(sampleBuffer) | ||
| 98 | -// let image = VisionImage(image: buffer!.image) | ||
| 99 | -// image.orientation = imageOrientation( | ||
| 100 | -// deviceOrientation: UIDevice.current.orientation, | ||
| 101 | -// defaultOrientation: .portrait | ||
| 102 | -// ) | ||
| 103 | -// | ||
| 104 | -// let scanner = BarcodeScanner.barcodeScanner() | ||
| 105 | -// scanner.process(image) { [self] barcodes, error in | ||
| 106 | -// if error == nil && barcodes != nil { | ||
| 107 | -// for barcode in barcodes! { | ||
| 108 | -// let event: [String: Any?] = ["name": "barcode", "data": barcode.data] | ||
| 109 | -// sink?(event) | ||
| 110 | -// } | ||
| 111 | -// } | ||
| 112 | -// analyzing = false | ||
| 113 | -// } | ||
| 114 | -// default: // none | ||
| 115 | -// break | ||
| 116 | -// } | ||
| 117 | -// } | 86 | + // Gets called when a new image is added to the buffer |
| 87 | + public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | ||
| 88 | + | ||
| 89 | + latestBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) | ||
| 90 | + registry.textureFrameAvailable(textureId) | ||
| 91 | + | ||
| 92 | + switch analyzeMode { | ||
| 93 | + case 1: // barcode | ||
| 94 | + if analyzing { | ||
| 95 | + break | ||
| 96 | + } | ||
| 97 | + analyzing = true | ||
| 98 | + let buffer = CMSampleBufferGetImageBuffer(sampleBuffer) | ||
| 99 | + let image = VisionImage(image: buffer!.image) | ||
| 100 | + image.orientation = imageOrientation( | ||
| 101 | + deviceOrientation: UIDevice.current.orientation, | ||
| 102 | + defaultOrientation: .portrait | ||
| 103 | + ) | ||
| 104 | + | ||
| 105 | + let scanner = BarcodeScanner.barcodeScanner() | ||
| 106 | + scanner.process(image) { [self] barcodes, error in | ||
| 107 | + if error == nil && barcodes != nil { | ||
| 108 | + for barcode in barcodes! { | ||
| 109 | + let event: [String: Any?] = ["name": "barcode", "data": barcode.data] | ||
| 110 | + sink?(event) | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | + analyzing = false | ||
| 114 | + } | ||
| 115 | + default: // none | ||
| 116 | + break | ||
| 117 | + } | ||
| 118 | + } | ||
| 118 | 119 | ||
| 119 | -// func imageOrientation( | ||
| 120 | -// deviceOrientation: UIDeviceOrientation, | ||
| 121 | -// defaultOrientation: UIDeviceOrientation | ||
| 122 | -// ) -> UIImage.Orientation { | ||
| 123 | -// switch deviceOrientation { | ||
| 124 | -// case .portrait: | ||
| 125 | -// return position == .front ? .leftMirrored : .right | ||
| 126 | -// case .landscapeLeft: | ||
| 127 | -// return position == .front ? .downMirrored : .up | ||
| 128 | -// case .portraitUpsideDown: | ||
| 129 | -// return position == .front ? .rightMirrored : .left | ||
| 130 | -// case .landscapeRight: | ||
| 131 | -// return position == .front ? .upMirrored : .down | ||
| 132 | -// case .faceDown, .faceUp, .unknown: | ||
| 133 | -// return .up | ||
| 134 | -// @unknown default: | ||
| 135 | -// return imageOrientation(deviceOrientation: defaultOrientation, defaultOrientation: .portrait) | ||
| 136 | -// } | ||
| 137 | -// } | 120 | + func imageOrientation( |
| 121 | + deviceOrientation: UIDeviceOrientation, | ||
| 122 | + defaultOrientation: UIDeviceOrientation | ||
| 123 | + ) -> UIImage.Orientation { | ||
| 124 | + switch deviceOrientation { | ||
| 125 | + case .portrait: | ||
| 126 | + return position == .front ? .leftMirrored : .right | ||
| 127 | + case .landscapeLeft: | ||
| 128 | + return position == .front ? .downMirrored : .up | ||
| 129 | + case .portraitUpsideDown: | ||
| 130 | + return position == .front ? .rightMirrored : .left | ||
| 131 | + case .landscapeRight: | ||
| 132 | + return position == .front ? .upMirrored : .down | ||
| 133 | + case .faceDown, .faceUp, .unknown: | ||
| 134 | + return .up | ||
| 135 | + @unknown default: | ||
| 136 | + return imageOrientation(deviceOrientation: defaultOrientation, defaultOrientation: .portrait) | ||
| 137 | + } | ||
| 138 | + } | ||
| 138 | 139 | ||
| 139 | func checkPermission(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | 140 | func checkPermission(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { |
| 140 | let status = AVCaptureDevice.authorizationStatus(for: .video) | 141 | let status = AVCaptureDevice.authorizationStatus(for: .video) |
| @@ -158,22 +159,35 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -158,22 +159,35 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 158 | 159 | ||
| 159 | let argReader = MapArgumentReader(call.arguments as? [String: Any]) | 160 | let argReader = MapArgumentReader(call.arguments as? [String: Any]) |
| 160 | 161 | ||
| 161 | - guard let ratio = argReader.int(key: "ratio"), | ||
| 162 | - let torch = argReader.int(key: "torch"), | ||
| 163 | - let facing = argReader.int(key: "facing") else { | ||
| 164 | - result(FlutterError(code: "INVALID_ARGUMENT", message: "Missing a required argument", details: "Expecting targetWidth, targetHeight, formats, and optionally heartbeatTimeout")) | ||
| 165 | - return | ||
| 166 | - } | ||
| 167 | - | 162 | +// let ratio: Int = argReader.int(key: "ratio") |
| 163 | + let torch: Bool = argReader.bool(key: "torch") ?? false | ||
| 164 | + let facing: Int = argReader.int(key: "facing") ?? 1 | ||
| 165 | + | ||
| 166 | + // Set the camera to use | ||
| 168 | position = facing == 0 ? AVCaptureDevice.Position.front : .back | 167 | position = facing == 0 ? AVCaptureDevice.Position.front : .back |
| 168 | + | ||
| 169 | + // Open the camera device | ||
| 169 | if #available(iOS 10.0, *) { | 170 | if #available(iOS 10.0, *) { |
| 170 | device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: position).devices.first | 171 | device = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: position).devices.first |
| 171 | } else { | 172 | } else { |
| 172 | device = AVCaptureDevice.devices(for: .video).filter({$0.position == position}).first | 173 | device = AVCaptureDevice.devices(for: .video).filter({$0.position == position}).first |
| 173 | } | 174 | } |
| 175 | + | ||
| 176 | + // Enable the torch if parameter is set and torch is available | ||
| 177 | + if (device.hasTorch && device.isTorchAvailable) { | ||
| 178 | + do { | ||
| 179 | + try device.lockForConfiguration() | ||
| 180 | + device.torchMode = torch ? .on : .off | ||
| 181 | + device.unlockForConfiguration() | ||
| 182 | + } catch { | ||
| 183 | + error.throwNative(result) | ||
| 184 | + } | ||
| 185 | + } | ||
| 186 | + | ||
| 174 | device.addObserver(self, forKeyPath: #keyPath(AVCaptureDevice.torchMode), options: .new, context: nil) | 187 | device.addObserver(self, forKeyPath: #keyPath(AVCaptureDevice.torchMode), options: .new, context: nil) |
| 175 | captureSession.beginConfiguration() | 188 | captureSession.beginConfiguration() |
| 176 | - // Add device input. | 189 | + |
| 190 | + // Add device input | ||
| 177 | do { | 191 | do { |
| 178 | let input = try AVCaptureDeviceInput(device: device) | 192 | let input = try AVCaptureDeviceInput(device: device) |
| 179 | captureSession.addInput(input) | 193 | captureSession.addInput(input) |
| @@ -205,7 +219,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -205,7 +219,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 205 | result(answer) | 219 | result(answer) |
| 206 | } | 220 | } |
| 207 | 221 | ||
| 208 | - func torchNative(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | 222 | + func switchTorch(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { |
| 209 | do { | 223 | do { |
| 210 | try device.lockForConfiguration() | 224 | try device.lockForConfiguration() |
| 211 | device.torchMode = call.arguments as! Int == 1 ? .on : .off | 225 | device.torchMode = call.arguments as! Int == 1 ? .on : .off |
| @@ -216,12 +230,12 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -216,12 +230,12 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 216 | } | 230 | } |
| 217 | } | 231 | } |
| 218 | 232 | ||
| 219 | - func analyzeNative(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | 233 | + func switchAnalyzeMode(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { |
| 220 | analyzeMode = call.arguments as! Int | 234 | analyzeMode = call.arguments as! Int |
| 221 | result(nil) | 235 | result(nil) |
| 222 | } | 236 | } |
| 223 | 237 | ||
| 224 | - func stopNative(_ result: FlutterResult) { | 238 | + func stop(_ result: FlutterResult) { |
| 225 | captureSession.stopRunning() | 239 | captureSession.stopRunning() |
| 226 | for input in captureSession.inputs { | 240 | for input in captureSession.inputs { |
| 227 | captureSession.removeInput(input) | 241 | captureSession.removeInput(input) |
| @@ -241,6 +255,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -241,6 +255,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 241 | result(nil) | 255 | result(nil) |
| 242 | } | 256 | } |
| 243 | 257 | ||
| 258 | + // Observer for torch state | ||
| 244 | public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { | 259 | public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { |
| 245 | switch keyPath { | 260 | switch keyPath { |
| 246 | case "torchMode": | 261 | case "torchMode": |
| @@ -269,6 +284,10 @@ class MapArgumentReader { | @@ -269,6 +284,10 @@ class MapArgumentReader { | ||
| 269 | func int(key: String) -> Int? { | 284 | func int(key: String) -> Int? { |
| 270 | return (args?[key] as? NSNumber)?.intValue | 285 | return (args?[key] as? NSNumber)?.intValue |
| 271 | } | 286 | } |
| 287 | + | ||
| 288 | + func bool(key: String) -> Bool? { | ||
| 289 | + return (args?[key] as? NSNumber)?.boolValue | ||
| 290 | + } | ||
| 272 | 291 | ||
| 273 | func stringArray(key: String) -> [String]? { | 292 | func stringArray(key: String) -> [String]? { |
| 274 | return args?[key] as? [String] | 293 | return args?[key] as? [String] |
| @@ -2,4 +2,4 @@ library mobile_scanner; | @@ -2,4 +2,4 @@ library mobile_scanner; | ||
| 2 | 2 | ||
| 3 | export 'src/mobile_scanner.dart'; | 3 | export 'src/mobile_scanner.dart'; |
| 4 | export 'src/mobile_scanner_controller.dart'; | 4 | export 'src/mobile_scanner_controller.dart'; |
| 5 | -export 'src/objects/barcode.dart'; | ||
| 5 | +export 'src/objects/barcode.dart'; |
| @@ -3,10 +3,7 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | @@ -3,10 +3,7 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 3 | 3 | ||
| 4 | import 'mobile_scanner_arguments.dart'; | 4 | import 'mobile_scanner_arguments.dart'; |
| 5 | 5 | ||
| 6 | -enum Ratio { | ||
| 7 | - ratio_4_3, | ||
| 8 | - ratio_16_9 | ||
| 9 | -} | 6 | +enum Ratio { ratio_4_3, ratio_16_9 } |
| 10 | 7 | ||
| 11 | /// A widget showing a live camera preview. | 8 | /// A widget showing a live camera preview. |
| 12 | class MobileScanner extends StatefulWidget { | 9 | class MobileScanner extends StatefulWidget { |
| @@ -18,7 +15,8 @@ class MobileScanner extends StatefulWidget { | @@ -18,7 +15,8 @@ class MobileScanner extends StatefulWidget { | ||
| 18 | /// Create a [MobileScanner] with a [controller], the [controller] must has been initialized. | 15 | /// Create a [MobileScanner] with a [controller], the [controller] must has been initialized. |
| 19 | const MobileScanner( | 16 | const MobileScanner( |
| 20 | {Key? key, this.onDetect, this.controller, this.fit = BoxFit.cover}) | 17 | {Key? key, this.onDetect, this.controller, this.fit = BoxFit.cover}) |
| 21 | - : assert((controller != null )), super(key: key); | 18 | + : assert((controller != null)), |
| 19 | + super(key: key); | ||
| 22 | 20 | ||
| 23 | @override | 21 | @override |
| 24 | State<MobileScanner> createState() => _MobileScannerState(); | 22 | State<MobileScanner> createState() => _MobileScannerState(); |
| @@ -91,4 +89,4 @@ class _MobileScannerState extends State<MobileScanner> | @@ -91,4 +89,4 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 91 | controller.dispose(); | 89 | controller.dispose(); |
| 92 | super.dispose(); | 90 | super.dispose(); |
| 93 | } | 91 | } |
| 94 | -} | ||
| 92 | +} |
| @@ -11,5 +11,6 @@ class MobileScannerArguments { | @@ -11,5 +11,6 @@ class MobileScannerArguments { | ||
| 11 | final bool hasTorch; | 11 | final bool hasTorch; |
| 12 | 12 | ||
| 13 | /// Create a [MobileScannerArguments]. | 13 | /// Create a [MobileScannerArguments]. |
| 14 | - MobileScannerArguments({required this.textureId,required this.size, required this.hasTorch}); | 14 | + MobileScannerArguments( |
| 15 | + {required this.textureId, required this.size, required this.hasTorch}); | ||
| 15 | } | 16 | } |
| @@ -38,7 +38,6 @@ class MobileScannerController { | @@ -38,7 +38,6 @@ class MobileScannerController { | ||
| 38 | int? _controllerHashcode; | 38 | int? _controllerHashcode; |
| 39 | StreamSubscription? events; | 39 | StreamSubscription? events; |
| 40 | 40 | ||
| 41 | - | ||
| 42 | final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null); | 41 | final ValueNotifier<MobileScannerArguments?> args = ValueNotifier(null); |
| 43 | final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off); | 42 | final ValueNotifier<TorchState> torchState = ValueNotifier(TorchState.off); |
| 44 | late final ValueNotifier<CameraFacing> cameraFacingState; | 43 | late final ValueNotifier<CameraFacing> cameraFacingState; |
| @@ -107,7 +106,8 @@ class MobileScannerController { | @@ -107,7 +106,8 @@ class MobileScannerController { | ||
| 107 | 106 | ||
| 108 | setAnalyzeMode(AnalyzeMode.barcode.index); | 107 | setAnalyzeMode(AnalyzeMode.barcode.index); |
| 109 | // Check authorization status | 108 | // Check authorization status |
| 110 | - MobileScannerState state = MobileScannerState.values[await methodChannel.invokeMethod('state')]; | 109 | + MobileScannerState state = |
| 110 | + MobileScannerState.values[await methodChannel.invokeMethod('state')]; | ||
| 111 | switch (state) { | 111 | switch (state) { |
| 112 | case MobileScannerState.undetermined: | 112 | case MobileScannerState.undetermined: |
| 113 | final bool result = await methodChannel.invokeMethod('request'); | 113 | final bool result = await methodChannel.invokeMethod('request'); |
| @@ -129,13 +129,18 @@ class MobileScannerController { | @@ -129,13 +129,18 @@ class MobileScannerController { | ||
| 129 | if (torchEnabled != null) arguments['torch'] = torchEnabled; | 129 | if (torchEnabled != null) arguments['torch'] = torchEnabled; |
| 130 | 130 | ||
| 131 | // Start the camera with arguments | 131 | // Start the camera with arguments |
| 132 | - final Map<String, dynamic>? startResult = await methodChannel.invokeMapMethod<String, dynamic>( | ||
| 133 | - 'start', arguments); | 132 | + final Map<String, dynamic>? startResult = await methodChannel |
| 133 | + .invokeMapMethod<String, dynamic>('start', arguments); | ||
| 134 | 134 | ||
| 135 | - if (startResult == null) throw PlatformException(code: 'INITIALIZATION ERROR'); | 135 | + if (startResult == null) { |
| 136 | + throw PlatformException(code: 'INITIALIZATION ERROR'); | ||
| 137 | + } | ||
| 136 | 138 | ||
| 137 | hasTorch = startResult['torchable']; | 139 | hasTorch = startResult['torchable']; |
| 138 | - args.value = MobileScannerArguments(textureId: startResult['textureId'], size: toSize(startResult['size']), hasTorch: hasTorch); | 140 | + args.value = MobileScannerArguments( |
| 141 | + textureId: startResult['textureId'], | ||
| 142 | + size: toSize(startResult['size']), | ||
| 143 | + hasTorch: hasTorch); | ||
| 139 | } | 144 | } |
| 140 | 145 | ||
| 141 | Future<void> stop() async => await methodChannel.invokeMethod('stop'); | 146 | Future<void> stop() async => await methodChannel.invokeMethod('stop'); |
| @@ -157,7 +162,8 @@ class MobileScannerController { | @@ -157,7 +162,8 @@ class MobileScannerController { | ||
| 157 | Future<void> switchCamera() async { | 162 | Future<void> switchCamera() async { |
| 158 | ensure('switchCamera'); | 163 | ensure('switchCamera'); |
| 159 | await stop(); | 164 | await stop(); |
| 160 | - facing = facing == CameraFacing.back ? CameraFacing.front : CameraFacing.back; | 165 | + facing = |
| 166 | + facing == CameraFacing.back ? CameraFacing.front : CameraFacing.back; | ||
| 161 | start(); | 167 | start(); |
| 162 | } | 168 | } |
| 163 | 169 |
| @@ -490,7 +490,7 @@ enum BarcodeFormat { | @@ -490,7 +490,7 @@ enum BarcodeFormat { | ||
| 490 | /// Barcode format constant for Data Matrix. | 490 | /// Barcode format constant for Data Matrix. |
| 491 | /// | 491 | /// |
| 492 | /// Constant Value: 16 | 492 | /// Constant Value: 16 |
| 493 | - data_matrix, | 493 | + dataMatrix, |
| 494 | 494 | ||
| 495 | /// Barcode format constant for EAN-13. | 495 | /// Barcode format constant for EAN-13. |
| 496 | /// | 496 | /// |
| @@ -510,17 +510,17 @@ enum BarcodeFormat { | @@ -510,17 +510,17 @@ enum BarcodeFormat { | ||
| 510 | /// Barcode format constant for QR Code. | 510 | /// Barcode format constant for QR Code. |
| 511 | /// | 511 | /// |
| 512 | /// Constant Value: 256 | 512 | /// Constant Value: 256 |
| 513 | - qr_code, | 513 | + qrCode, |
| 514 | 514 | ||
| 515 | /// Barcode format constant for UPC-A. | 515 | /// Barcode format constant for UPC-A. |
| 516 | /// | 516 | /// |
| 517 | /// Constant Value: 512 | 517 | /// Constant Value: 512 |
| 518 | - upc_a, | 518 | + upcA, |
| 519 | 519 | ||
| 520 | /// Barcode format constant for UPC-E. | 520 | /// Barcode format constant for UPC-E. |
| 521 | /// | 521 | /// |
| 522 | /// Constant Value: 1024 | 522 | /// Constant Value: 1024 |
| 523 | - upc_e, | 523 | + upcE, |
| 524 | 524 | ||
| 525 | /// Barcode format constant for PDF-417. | 525 | /// Barcode format constant for PDF-417. |
| 526 | /// | 526 | /// |
| @@ -29,7 +29,7 @@ BarcodeFormat toFormat(int value) { | @@ -29,7 +29,7 @@ BarcodeFormat toFormat(int value) { | ||
| 29 | case 8: | 29 | case 8: |
| 30 | return BarcodeFormat.codebar; | 30 | return BarcodeFormat.codebar; |
| 31 | case 16: | 31 | case 16: |
| 32 | - return BarcodeFormat.data_matrix; | 32 | + return BarcodeFormat.dataMatrix; |
| 33 | case 32: | 33 | case 32: |
| 34 | return BarcodeFormat.ean13; | 34 | return BarcodeFormat.ean13; |
| 35 | case 64: | 35 | case 64: |
| @@ -37,11 +37,11 @@ BarcodeFormat toFormat(int value) { | @@ -37,11 +37,11 @@ BarcodeFormat toFormat(int value) { | ||
| 37 | case 128: | 37 | case 128: |
| 38 | return BarcodeFormat.itf; | 38 | return BarcodeFormat.itf; |
| 39 | case 256: | 39 | case 256: |
| 40 | - return BarcodeFormat.qr_code; | 40 | + return BarcodeFormat.qrCode; |
| 41 | case 512: | 41 | case 512: |
| 42 | - return BarcodeFormat.upc_a; | 42 | + return BarcodeFormat.upcA; |
| 43 | case 1024: | 43 | case 1024: |
| 44 | - return BarcodeFormat.upc_e; | 44 | + return BarcodeFormat.upcE; |
| 45 | case 2048: | 45 | case 2048: |
| 46 | return BarcodeFormat.pdf417; | 46 | return BarcodeFormat.pdf417; |
| 47 | case 4096: | 47 | case 4096: |
| 1 | import 'package:flutter/services.dart'; | 1 | import 'package:flutter/services.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; | 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | -import 'package:mobile_scanner/src/mobile_scanner.dart'; | ||
| 4 | 3 | ||
| 5 | void main() { | 4 | void main() { |
| 6 | const MethodChannel channel = MethodChannel('mobile_scanner'); | 5 | const MethodChannel channel = MethodChannel('mobile_scanner'); |
| @@ -16,5 +15,4 @@ void main() { | @@ -16,5 +15,4 @@ void main() { | ||
| 16 | tearDown(() { | 15 | tearDown(() { |
| 17 | channel.setMockMethodCallHandler(null); | 16 | channel.setMockMethodCallHandler(null); |
| 18 | }); | 17 | }); |
| 19 | - | ||
| 20 | } | 18 | } |
-
Please register or login to post a comment