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
2023-10-22 17:01:35 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
caaaca7891ec8e0e6c3faf451c7b1bb4ad56238e
caaaca78
1 parent
eca23318
format SwiftMobileScannerPlugin.swift
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
ios/Classes/SwiftMobileScannerPlugin.swift
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
caaaca7
...
...
@@ -14,7 +14,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
/// The points for the scan window.
static
var
scanWindow
:
[
CGFloat
]?
private
static
func
isBarcodeInScanWindow
(
barcode
:
Barcode
,
imageSize
:
CGSize
)
->
Bool
{
let
scanwindow
=
SwiftMobileScannerPlugin
.
scanWindow
!
let
barcodeminX
=
barcode
.
cornerPoints
!
[
0
]
.
cgPointValue
.
x
...
...
@@ -24,7 +24,6 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
let
barcodeheight
=
barcode
.
cornerPoints
!
[
3
]
.
cgPointValue
.
y
-
barcodeminY
let
barcodeBox
=
CGRect
(
x
:
barcodeminX
,
y
:
barcodeminY
,
width
:
barcodewidth
,
height
:
barcodeheight
)
let
minX
=
scanwindow
[
0
]
*
imageSize
.
width
let
minY
=
scanwindow
[
1
]
*
imageSize
.
height
...
...
@@ -64,14 +63,13 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
self
.
barcodeHandler
=
barcodeHandler
super
.
init
()
}
public
static
func
register
(
with
registrar
:
FlutterPluginRegistrar
)
{
let
channel
=
FlutterMethodChannel
(
name
:
"dev.steenbakker.mobile_scanner/scanner/method"
,
binaryMessenger
:
registrar
.
messenger
())
let
instance
=
SwiftMobileScannerPlugin
(
barcodeHandler
:
BarcodeHandler
(
registrar
:
registrar
),
registry
:
registrar
.
textures
())
let
methodChannel
=
FlutterMethodChannel
(
name
:
"dev.steenbakker.mobile_scanner/scanner/method"
,
binaryMessenger
:
registrar
.
messenger
())
registrar
.
addMethodCallDelegate
(
instance
,
channel
:
methodChannel
)
registrar
.
addMethodCallDelegate
(
instance
,
channel
:
channel
)
}
public
func
handle
(
_
call
:
FlutterMethodCall
,
result
:
@escaping
FlutterResult
)
{
switch
call
.
method
{
case
"state"
:
...
...
@@ -96,7 +94,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
result
(
FlutterMethodNotImplemented
)
}
}
/// Parses all parameters and starts the mobileScanner
private
func
start
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
let
torch
:
Bool
=
(
call
.
arguments
as!
Dictionary
<
String
,
Any
?
>
)[
"torch"
]
as?
Bool
??
false
...
...
@@ -106,18 +104,17 @@ public class SwiftMobileScannerPlugin: 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
/
1000
)
let
formatList
=
formats
.
map
{
format
in
return
BarcodeFormat
(
rawValue
:
format
)}
var
barcodeOptions
:
BarcodeScannerOptions
?
=
nil
if
(
formatList
.
count
!=
0
)
{
var
barcodeFormats
:
BarcodeFormat
=
[]
for
index
in
formats
{
barcodeFormats
.
insert
(
BarcodeFormat
(
rawValue
:
index
))
}
barcodeOptions
=
BarcodeScannerOptions
(
formats
:
barcodeFormats
)
}
if
(
formatList
.
count
!=
0
)
{
var
barcodeFormats
:
BarcodeFormat
=
[]
for
index
in
formats
{
barcodeFormats
.
insert
(
BarcodeFormat
(
rawValue
:
index
))
}
barcodeOptions
=
BarcodeScannerOptions
(
formats
:
barcodeFormats
)
}
let
position
=
facing
==
0
?
AVCaptureDevice
.
Position
.
front
:
.
back
let
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
(
rawValue
:
speed
)
!
...
...
@@ -174,8 +171,8 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
let
scale
=
call
.
arguments
as?
CGFloat
if
(
scale
==
nil
)
{
result
(
FlutterError
(
code
:
"MobileScanner"
,
message
:
"You must provide a scale when calling setScale!"
,
details
:
nil
))
message
:
"You must provide a scale when calling setScale!"
,
details
:
nil
))
return
}
do
{
...
...
@@ -216,7 +213,6 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
result
(
nil
)
}
/// Toggles the torch
func
updateScanWindow
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
let
scanWindowData
:
Array
?
=
(
call
.
arguments
as?
[
String
:
Any
])?[
"rect"
]
as?
[
CGFloat
]
...
...
Please
register
or
login
to post a comment