Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2024-06-18 10:34:59 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b5ce2297a091feffb463a2cbda6c2be9ba639b3a
b5ce2297
1 parent
9d1a70fc
adjust analyze image to throw barcode exceptions if needed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
16 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
ios/Classes/MobileScannerPlugin.swift
lib/src/method_channel/mobile_scanner_method_channel.dart
lib/src/mobile_scanner_controller.dart
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
View file @
b5ce229
...
...
@@ -29,7 +29,7 @@ class MobileScannerHandler(
private val analyzeImageErrorCallback: AnalyzerErrorCallback = {
Handler(Looper.getMainLooper()).post {
analyzerResult?.error(MobileScannerErrorCodes.
GENERIC
_ERROR, it, null)
analyzerResult?.error(MobileScannerErrorCodes.
BARCODE
_ERROR, it, null)
analyzerResult = null
}
}
...
...
ios/Classes/MobileScannerPlugin.swift
View file @
b5ce229
...
...
@@ -269,7 +269,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
barcodeScannerOptions
:
scannerOptions
,
callback
:
{
barcodes
,
error
in
if
error
!=
nil
{
DispatchQueue
.
main
.
async
{
result
(
FlutterError
(
code
:
MobileScannerErrorCodes
.
GENERIC
_ERROR
,
result
(
FlutterError
(
code
:
MobileScannerErrorCodes
.
BARCODE
_ERROR
,
message
:
error
?
.
localizedDescription
,
details
:
nil
))
}
...
...
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
b5ce229
...
...
@@ -164,21 +164,30 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
String
path
,
{
List
<
BarcodeFormat
>
formats
=
const
<
BarcodeFormat
>[],
})
async
{
final
Map
<
Object
?,
Object
?>?
result
=
await
methodChannel
.
invokeMapMethod
<
Object
?,
Object
?>(
'analyzeImage'
,
{
'filePath'
:
path
,
'formats'
:
formats
.
isEmpty
?
null
:
[
for
(
final
BarcodeFormat
format
in
formats
)
if
(
format
!=
BarcodeFormat
.
unknown
)
format
.
rawValue
,
],
},
);
try
{
final
Map
<
Object
?,
Object
?>?
result
=
await
methodChannel
.
invokeMapMethod
<
Object
?,
Object
?>(
'analyzeImage'
,
{
'filePath'
:
path
,
'formats'
:
formats
.
isEmpty
?
null
:
[
for
(
final
BarcodeFormat
format
in
formats
)
if
(
format
!=
BarcodeFormat
.
unknown
)
format
.
rawValue
,
],
},
);
return
_parseBarcode
(
result
);
return
_parseBarcode
(
result
);
}
on
PlatformException
catch
(
error
)
{
// Handle any errors from analyze image requests.
if
(
error
.
code
==
kBarcodeErrorEventName
)
{
throw
MobileScannerBarcodeException
(
error
.
message
);
}
return
null
;
}
}
@override
...
...
lib/src/mobile_scanner_controller.dart
View file @
b5ce229
...
...
@@ -191,6 +191,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
/// This is only supported on Android, iOS and MacOS.
///
/// Returns the [BarcodeCapture] that was found in the image.
///
/// If an error occurred during the analysis of the image,
/// a [MobileScannerBarcodeException] error is thrown.
Future
<
BarcodeCapture
?>
analyzeImage
(
String
path
)
{
return
MobileScannerPlatform
.
instance
.
analyzeImage
(
path
);
}
...
...
Please
register
or
login
to post a comment