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:35:37 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2e9e246f695f3ca424162d9bf537e1b88c4924ae
2e9e246f
1 parent
f772f294
fix return image being ignored on iOS
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
7 deletions
ios/Classes/MobileScanner.swift
ios/Classes/MobileScannerPlugin.swift
ios/Classes/MobileScanner.swift
View file @
2e9e246
...
...
@@ -25,9 +25,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
/// Barcode scanner for results
var
scanner
=
BarcodeScanner
.
barcodeScanner
()
/// Return image buffer with the Barcode event
var
returnImage
:
Bool
=
false
/// Default position of camera
var
videoPosition
:
AVCaptureDevice
.
Position
=
AVCaptureDevice
.
Position
.
back
...
...
@@ -172,7 +169,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
/// Start scanning for barcodes
func
start
(
barcodeScannerOptions
:
BarcodeScannerOptions
?,
returnImage
:
Bool
,
cameraPosition
:
AVCaptureDevice
.
Position
,
torch
:
Bool
,
detectionSpeed
:
DetectionSpeed
,
completion
:
@escaping
(
MobileScannerStartParameters
)
->
())
throws
{
func
start
(
barcodeScannerOptions
:
BarcodeScannerOptions
?,
cameraPosition
:
AVCaptureDevice
.
Position
,
torch
:
Bool
,
detectionSpeed
:
DetectionSpeed
,
completion
:
@escaping
(
MobileScannerStartParameters
)
->
())
throws
{
self
.
detectionSpeed
=
detectionSpeed
if
(
device
!=
nil
||
captureSession
!=
nil
)
{
throw
MobileScannerError
.
alreadyStarted
...
...
ios/Classes/MobileScannerPlugin.swift
View file @
2e9e246
...
...
@@ -11,6 +11,10 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
/// The handler sends all information via an event channel back to Flutter
private
let
barcodeHandler
:
BarcodeHandler
/// Whether to return the input image with the barcode event.
/// This is static to avoid accessing `self` in the callback in the constructor.
private
static
var
returnImage
:
Bool
=
false
/// The points for the scan window.
static
var
scanWindow
:
[
CGFloat
]?
...
...
@@ -58,9 +62,27 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
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
])
if
(
barcodesMap
.
isEmpty
)
{
return
}
if
(
!
MobileScannerPlugin
.
returnImage
)
{
barcodeHandler
.
publishEvent
([
"name"
:
"barcode"
,
"data"
:
barcodesMap
,
])
return
}
barcodeHandler
.
publishEvent
([
"name"
:
"barcode"
,
"data"
:
barcodesMap
,
"image"
:
[
"bytes"
:
FlutterStandardTypedData
(
bytes
:
image
.
jpegData
(
compressionQuality
:
0.8
)
!
),
"width"
:
image
.
size
.
width
,
"height"
:
image
.
size
.
height
,
],
])
},
torchModeChangeCallback
:
{
torchState
in
barcodeHandler
.
publishEvent
([
"name"
:
"torchState"
,
"data"
:
torchState
])
},
zoomScaleChangeCallback
:
{
zoomScale
in
...
...
@@ -110,6 +132,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
let
speed
:
Int
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"speed"
]
as?
Int
??
0
let
timeoutMs
:
Int
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"timeout"
]
as?
Int
??
0
self
.
mobileScanner
.
timeoutSeconds
=
Double
(
timeoutMs
)
/
Double
(
1000
)
MobileScannerPlugin
.
returnImage
=
returnImage
let
formatList
=
formats
.
map
{
format
in
return
BarcodeFormat
(
rawValue
:
format
)}
var
barcodeOptions
:
BarcodeScannerOptions
?
=
nil
...
...
@@ -126,7 +149,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin {
let
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
(
rawValue
:
speed
)
!
do
{
try
mobileScanner
.
start
(
barcodeScannerOptions
:
barcodeOptions
,
returnImage
:
returnImage
,
cameraPosition
:
position
,
torch
:
torch
,
detectionSpeed
:
detectionSpeed
)
{
parameters
in
try
mobileScanner
.
start
(
barcodeScannerOptions
:
barcodeOptions
,
cameraPosition
:
position
,
torch
:
torch
,
detectionSpeed
:
detectionSpeed
)
{
parameters
in
DispatchQueue
.
main
.
async
{
result
([
"textureId"
:
parameters
.
textureId
,
...
...
Please
register
or
login
to post a comment