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-09-04 10:12:18 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f772f294568afc6835069eea6e587052ad5db1d3
f772f294
1 parent
fa23d7dd
fix early returns in iOS implementation of mobile scanner
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
20 deletions
ios/Classes/MobileScannerPlugin.swift
ios/Classes/MobileScannerPlugin.swift
View file @
f772f29
...
...
@@ -37,23 +37,29 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
init
(
barcodeHandler
:
BarcodeHandler
,
registry
:
FlutterTextureRegistry
)
{
self
.
mobileScanner
=
MobileScanner
(
registry
:
registry
,
mobileScannerCallback
:
{
barcodes
,
error
,
image
in
if
barcodes
!=
nil
{
let
barcodesMap
:
[
Any
?]
=
barcodes
!.
compactMap
{
barcode
in
if
(
MobileScannerPlugin
.
scanWindow
!=
nil
)
{
if
(
MobileScannerPlugin
.
isBarcodeInScanWindow
(
barcode
:
barcode
,
imageSize
:
image
.
size
))
{
return
barcode
.
data
}
else
{
return
nil
}
}
else
{
return
barcode
.
data
}
if
error
!=
nil
{
barcodeHandler
.
publishEvent
([
"name"
:
"error"
,
"data"
:
error
!.
localizedDescription
])
return
}
if
barcodes
==
nil
{
return
}
let
barcodesMap
:
[
Any
?]
=
barcodes
!.
compactMap
{
barcode
in
if
(
MobileScannerPlugin
.
scanWindow
==
nil
)
{
return
barcode
.
data
}
if
(
!
barcodesMap
.
isEmpty
)
{
barcodeHandler
.
publishEvent
([
"name"
:
"barcode"
,
"data"
:
barcodesMap
,
"image"
:
FlutterStandardTypedData
(
bytes
:
image
.
jpegData
(
compressionQuality
:
0.8
)
!
),
"width"
:
image
.
size
.
width
,
"height"
:
image
.
size
.
height
])
if
(
MobileScannerPlugin
.
isBarcodeInScanWindow
(
barcode
:
barcode
,
imageSize
:
image
.
size
))
{
return
barcode
.
data
}
}
else
if
(
error
!=
nil
){
barcodeHandler
.
publishEvent
([
"name"
:
"error"
,
"data"
:
error
!.
localizedDescription
])
return
nil
}
if
(
!
barcodesMap
.
isEmpty
)
{
barcodeHandler
.
publishEvent
([
"name"
:
"barcode"
,
"data"
:
barcodesMap
,
"image"
:
FlutterStandardTypedData
(
bytes
:
image
.
jpegData
(
compressionQuality
:
0.8
)
!
),
"width"
:
image
.
size
.
width
,
"height"
:
image
.
size
.
height
])
}
},
torchModeChangeCallback
:
{
torchState
in
barcodeHandler
.
publishEvent
([
"name"
:
"torchState"
,
"data"
:
torchState
])
...
...
@@ -257,12 +263,14 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
DispatchQueue
.
main
.
async
{
result
(
nil
)
}
}
else
{
let
barcodesMap
:
[
Any
?]
=
barcodes
!.
compactMap
{
barcode
in
barcode
.
data
}
DispatchQueue
.
main
.
async
{
result
([
"name"
:
"barcode"
,
"data"
:
barcodesMap
])
}
return
}
let
barcodesMap
:
[
Any
?]
=
barcodes
!.
compactMap
{
barcode
in
barcode
.
data
}
DispatchQueue
.
main
.
async
{
result
([
"name"
:
"barcode"
,
"data"
:
barcodesMap
])
}
})
}
...
...
Please
register
or
login
to post a comment