Showing
3 changed files
with
27 additions
and
4 deletions
| @@ -3,6 +3,7 @@ import 'dart:async'; | @@ -3,6 +3,7 @@ import 'dart:async'; | ||
| 3 | import 'package:flutter/foundation.dart'; | 3 | import 'package:flutter/foundation.dart'; |
| 4 | import 'package:flutter/services.dart'; | 4 | import 'package:flutter/services.dart'; |
| 5 | import 'package:flutter/widgets.dart'; | 5 | import 'package:flutter/widgets.dart'; |
| 6 | +import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
| 6 | import 'package:mobile_scanner/src/enums/mobile_scanner_authorization_state.dart'; | 7 | import 'package:mobile_scanner/src/enums/mobile_scanner_authorization_state.dart'; |
| 7 | import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; | 8 | import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; |
| 8 | import 'package:mobile_scanner/src/enums/torch_state.dart'; | 9 | import 'package:mobile_scanner/src/enums/torch_state.dart'; |
| @@ -140,11 +141,22 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | @@ -140,11 +141,22 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | ||
| 140 | } | 141 | } |
| 141 | 142 | ||
| 142 | @override | 143 | @override |
| 143 | - Future<BarcodeCapture?> analyzeImage(String path) async { | 144 | + Future<BarcodeCapture?> analyzeImage( |
| 145 | + String path, { | ||
| 146 | + List<BarcodeFormat> formats = const <BarcodeFormat>[], | ||
| 147 | + }) async { | ||
| 144 | final Map<Object?, Object?>? result = | 148 | final Map<Object?, Object?>? result = |
| 145 | await methodChannel.invokeMapMethod<Object?, Object?>( | 149 | await methodChannel.invokeMapMethod<Object?, Object?>( |
| 146 | 'analyzeImage', | 150 | 'analyzeImage', |
| 147 | - path, | 151 | + { |
| 152 | + 'filePath': path, | ||
| 153 | + 'formats': formats.isEmpty | ||
| 154 | + ? null | ||
| 155 | + : [ | ||
| 156 | + for (final BarcodeFormat format in formats) | ||
| 157 | + if (format != BarcodeFormat.unknown) format.rawValue, | ||
| 158 | + ], | ||
| 159 | + }, | ||
| 148 | ); | 160 | ); |
| 149 | 161 | ||
| 150 | return _parseBarcode(result); | 162 | return _parseBarcode(result); |
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
| 2 | +import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
| 2 | import 'package:mobile_scanner/src/enums/torch_state.dart'; | 3 | import 'package:mobile_scanner/src/enums/torch_state.dart'; |
| 3 | import 'package:mobile_scanner/src/method_channel/mobile_scanner_method_channel.dart'; | 4 | import 'package:mobile_scanner/src/method_channel/mobile_scanner_method_channel.dart'; |
| 4 | import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart'; | 5 | import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart'; |
| @@ -46,9 +47,15 @@ abstract class MobileScannerPlatform extends PlatformInterface { | @@ -46,9 +47,15 @@ abstract class MobileScannerPlatform extends PlatformInterface { | ||
| 46 | /// Analyze a local image file for barcodes. | 47 | /// Analyze a local image file for barcodes. |
| 47 | /// | 48 | /// |
| 48 | /// The [path] is the path to the file on disk. | 49 | /// The [path] is the path to the file on disk. |
| 50 | + /// The [formats] specify the barcode formats that should be detected. | ||
| 51 | + /// | ||
| 52 | + /// If [formats] is empty, all barcode formats will be detected. | ||
| 49 | /// | 53 | /// |
| 50 | /// Returns the barcodes that were found in the image. | 54 | /// Returns the barcodes that were found in the image. |
| 51 | - Future<BarcodeCapture?> analyzeImage(String path) { | 55 | + Future<BarcodeCapture?> analyzeImage( |
| 56 | + String path, { | ||
| 57 | + List<BarcodeFormat> formats = const <BarcodeFormat>[], | ||
| 58 | + }) { | ||
| 52 | throw UnimplementedError('analyzeImage() has not been implemented.'); | 59 | throw UnimplementedError('analyzeImage() has not been implemented.'); |
| 53 | } | 60 | } |
| 54 | 61 |
| @@ -4,6 +4,7 @@ import 'dart:ui_web' as ui_web; | @@ -4,6 +4,7 @@ import 'dart:ui_web' as ui_web; | ||
| 4 | 4 | ||
| 5 | import 'package:flutter/widgets.dart'; | 5 | import 'package:flutter/widgets.dart'; |
| 6 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | 6 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; |
| 7 | +import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
| 7 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; | 8 | import 'package:mobile_scanner/src/enums/camera_facing.dart'; |
| 8 | import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; | 9 | import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; |
| 9 | import 'package:mobile_scanner/src/enums/torch_state.dart'; | 10 | import 'package:mobile_scanner/src/enums/torch_state.dart'; |
| @@ -232,7 +233,10 @@ class MobileScannerWeb extends MobileScannerPlatform { | @@ -232,7 +233,10 @@ class MobileScannerWeb extends MobileScannerPlatform { | ||
| 232 | } | 233 | } |
| 233 | 234 | ||
| 234 | @override | 235 | @override |
| 235 | - Future<BarcodeCapture?> analyzeImage(String path) { | 236 | + Future<BarcodeCapture?> analyzeImage( |
| 237 | + String path, { | ||
| 238 | + List<BarcodeFormat> formats = const <BarcodeFormat>[], | ||
| 239 | + }) { | ||
| 236 | throw UnsupportedError('analyzeImage() is not supported on the web.'); | 240 | throw UnsupportedError('analyzeImage() is not supported on the web.'); |
| 237 | } | 241 | } |
| 238 | 242 |
-
Please register or login to post a comment