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-04-24 14:20:31 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
10d26f8529cf8cd9da264204c7ed28009e95edfe
10d26f85
1 parent
c5e02890
take into account the auto mode on iOS/MacOS
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
7 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
example/lib/scanner_button_widgets.dart
ios/Classes/MobileScanner.swift
lib/src/enums/torch_state.dart
macos/Classes/MobileScannerPlugin.swift
test/enums/torch_state_test.dart
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
View file @
10d26f8
...
...
@@ -74,6 +74,7 @@ class MobileScannerHandler(
private var mobileScanner: MobileScanner? = null
private val torchStateCallback: TorchStateCallback = {state: Int ->
// Off = 0, On = 1
barcodeHandler.publishEvent(mapOf("name" to "torchState", "data" to state))
}
...
...
example/lib/scanner_button_widgets.dart
View file @
10d26f8
...
...
@@ -138,6 +138,17 @@ class ToggleFlashlightButton extends StatelessWidget {
}
switch
(
state
.
torchState
)
{
case
TorchState
.
auto
:
return
IconButton
(
color:
Colors
.
white
,
iconSize:
32.0
,
icon:
const
Icon
(
Icons
.
flash_auto
),
onPressed:
()
async
{
// This button only turns off the auto mode.
// Perhaps we can switch between on / off / auto?
await
controller
.
toggleTorch
();
},
);
case
TorchState
.
off
:
return
IconButton
(
color:
Colors
.
white
,
...
...
ios/Classes/MobileScanner.swift
View file @
10d26f8
...
...
@@ -347,7 +347,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
public
override
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
switch
keyPath
{
case
"torchMode"
:
//
off = 0; on = 1; a
uto = 2
//
Off = 0, On = 1, A
uto = 2
let
state
=
change
?[
.
newKey
]
as?
Int
torchModeChangeCallback
(
state
)
case
"videoZoomFactor"
:
...
...
lib/src/enums/torch_state.dart
View file @
10d26f8
/// The state of the flashlight.
enum
TorchState
{
/// The flashlight turns on automatically in low light conditions.
///
/// This is currently only supported on iOS.
auto
(
2
),
/// The flashlight is off.
off
(
0
),
...
...
@@ -7,18 +12,20 @@ enum TorchState {
on
(
1
),
/// The flashlight is unavailable.
unavailable
(
2
);
unavailable
(
-
1
);
const
TorchState
(
this
.
rawValue
);
factory
TorchState
.
fromRawValue
(
int
value
)
{
switch
(
value
)
{
case
-
1
:
return
TorchState
.
unavailable
;
case
0
:
return
TorchState
.
off
;
case
1
:
return
TorchState
.
on
;
case
2
:
return
TorchState
.
unavailable
;
return
TorchState
.
auto
;
default
:
throw
ArgumentError
.
value
(
value
,
'value'
,
'Invalid raw value.'
);
}
...
...
macos/Classes/MobileScannerPlugin.swift
View file @
10d26f8
...
...
@@ -410,7 +410,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler,
public
override
func
observeValue
(
forKeyPath
keyPath
:
String
?,
of
object
:
Any
?,
change
:
[
NSKeyValueChangeKey
:
Any
]?,
context
:
UnsafeMutableRawPointer
?)
{
switch
keyPath
{
case
"torchMode"
:
//
off = 0 on = 1 a
uto = 2
//
Off = 0, On = 1, A
uto = 2
let
state
=
change
?[
.
newKey
]
as?
Int
let
event
:
[
String
:
Any
?]
=
[
"name"
:
"torchState"
,
"data"
:
state
]
sink
?(
event
)
...
...
test/enums/torch_state_test.dart
View file @
10d26f8
...
...
@@ -7,7 +7,8 @@ void main() {
const
values
=
<
int
,
TorchState
>{
0
:
TorchState
.
off
,
1
:
TorchState
.
on
,
2
:
TorchState
.
unavailable
,
2
:
TorchState
.
auto
,
-
1
:
TorchState
.
unavailable
,
};
for
(
final
MapEntry
<
int
,
TorchState
>
entry
in
values
.
entries
)
{
...
...
@@ -18,7 +19,7 @@ void main() {
});
test
(
'invalid raw value throws argument error'
,
()
{
const
int
negative
=
-
1
;
const
int
negative
=
-
2
;
const
int
outOfRange
=
3
;
expect
(()
=>
TorchState
.
fromRawValue
(
negative
),
throwsArgumentError
);
...
...
@@ -27,9 +28,10 @@ void main() {
test
(
'can be converted to raw value'
,
()
{
const
values
=
<
TorchState
,
int
>{
TorchState
.
unavailable
:
-
1
,
TorchState
.
off
:
0
,
TorchState
.
on
:
1
,
TorchState
.
unavailable
:
2
,
TorchState
.
auto
:
2
,
};
for
(
final
MapEntry
<
TorchState
,
int
>
entry
in
values
.
entries
)
{
...
...
Please
register
or
login
to post a comment