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
casvanluijtelaar
2022-06-09 10:28:56 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
55a5d7f8302a257d35894e35b149ca8f38f66361
55a5d7f8
1 parent
979d7f23
add macos support
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletions
lib/src/mobile_scanner_controller.dart
macos/Classes/MobileScannerPlugin.swift
lib/src/mobile_scanner_controller.dart
View file @
55a5d7f
...
...
@@ -50,7 +50,6 @@ class MobileScannerController {
final
List
<
BarcodeFormat
>?
formats
;
/// can be used to limit the scan area to a portion of the screen
/// only for Android and IOS!
final
Rect
?
scanWindow
;
CameraFacing
facing
;
...
...
macos/Classes/MobileScannerPlugin.swift
View file @
55a5d7f
import
AVFoundation
import
FlutterMacOS
import
Vision
import
UIKit
public
class
MobileScannerPlugin
:
NSObject
,
FlutterPlugin
,
FlutterStreamHandler
,
FlutterTexture
,
AVCaptureVideoDataOutputSampleBufferDelegate
{
...
...
@@ -21,6 +22,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
// Image to be sent to the texture
var
latestBuffer
:
CVImageBuffer
!
// optional window to limit scan search
var
scanWindow
:
CGRect
?
// var analyzeMode: Int = 0
var
analyzing
:
Bool
=
false
...
...
@@ -110,6 +114,14 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
if
error
==
nil
{
if
let
results
=
request
.
results
as?
[
VNBarcodeObservation
]
{
for
barcode
in
results
{
if
scanWindow
!=
nil
{
let
boundingBox
=
barcode
.
frame
if
!
scanWindow
!.
contains
(
boundingBox
)
{
continue
}
}
let
barcodeType
=
String
(
barcode
.
symbology
.
rawValue
)
.
replacingOccurrences
(
of
:
"VNBarcodeSymbology"
,
with
:
""
)
let
event
:
[
String
:
Any
?]
=
[
"name"
:
"barcodeMac"
,
"data"
:
[
"payload"
:
barcode
.
payloadStringValue
,
"symbology"
:
barcodeType
]]
self
.
sink
?(
event
)
...
...
@@ -175,6 +187,19 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
let
torch
:
Bool
=
argReader
.
bool
(
key
:
"torch"
)
??
false
let
facing
:
Int
=
argReader
.
int
(
key
:
"facing"
)
??
1
let
scanWindowData
:
Array
?
=
argReader
.
floatArray
(
key
:
"scanWindow"
)
if
(
scanWindowData
!=
nil
)
{
let
minX
=
scanWindowData
!
[
0
]
let
minY
=
scanWindowData
!
[
1
]
let
width
=
scanWindowData
!
[
2
]
-
minX
let
height
=
scanWindowData
!
[
3
]
-
minY
scanWindow
=
CGRect
(
x
:
minX
,
y
:
minY
,
width
:
width
,
height
:
height
)
}
// Set the camera to use
position
=
facing
==
0
?
AVCaptureDevice
.
Position
.
front
:
.
back
...
...
@@ -322,4 +347,8 @@ class MapArgumentReader {
return
args
?[
key
]
as?
[
String
]
}
func
floatArray
(
key
:
String
)
->
[
CGFloat
]?
{
return
args
?[
key
]
as?
[
CGFloat
]
}
}
...
...
Please
register
or
login
to post a comment