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-11-08 18:21:07 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cd7302f9a1130b419226b2d88568f9ff55cd0b42
cd7302f9
1 parent
b64e5fa6
fix state update in stop(); pass camera direction in switchCamera(); fix the tor…
…ch state for toggleTorch()
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
lib/src/mobile_scanner_controller.dart
lib/src/mobile_scanner_controller.dart
View file @
cd7302f
...
...
@@ -241,40 +241,48 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
///
/// After calling this method, the camera can be restarted using [start].
Future
<
void
>
stop
()
async
{
_disposeListeners
();
_throwIfNotInitialized
();
await
MobileScannerPlatform
.
instance
.
stop
();
// After the camera stopped, set the torch state to off,
// as the torch state callback is never called when the camera is stopped.
torchState
.
value
=
TorchState
.
off
;
value
=
value
.
copyWith
(
torchState:
TorchState
.
off
)
;
}
/// Switch between the front and back camera.
Future
<
void
>
switchCamera
()
async
{
await
MobileScannerPlatform
.
instance
.
stop
();
_throwIfNotInitialized
();
final
CameraFacing
cameraDirection
;
await
stop
()
;
// TODO: update the camera facing direction state
final
CameraFacing
cameraDirection
=
value
.
cameraDirection
;
await
start
(
cameraDirection:
cameraDirection
);
await
start
(
cameraDirection:
cameraDirection
==
CameraFacing
.
front
?
CameraFacing
.
back
:
CameraFacing
.
front
,
);
}
/// Switches the flashlight on or off.
///
/// Does nothing if the device has no torch.
Future
<
void
>
toggleTorch
()
async
{
final
bool
hasTorch
;
_throwIfNotInitialized
();
final
TorchState
torchState
=
value
.
torchState
;
if
(
!
hasTorch
)
{
if
(
torchState
==
TorchState
.
unavailable
)
{
return
;
}
final
TorchState
newState
=
torchState
.
value
==
TorchState
.
off
?
TorchState
.
on
:
TorchState
.
off
;
final
TorchState
newState
=
torchState
==
TorchState
.
off
?
TorchState
.
on
:
TorchState
.
off
;
// Update the torch state to the new state.
// When the platform has updated the torch state,
// it will send an update through the torch state event stream.
await
MobileScannerPlatform
.
instance
.
setTorchState
();
await
MobileScannerPlatform
.
instance
.
setTorchState
(
newState
);
}
@override
...
...
Please
register
or
login
to post a comment