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-26 13:36:05 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
35dc61cb55de4bd43e41f8b899970d26a8a6427b
35dc61cb
1 parent
10d26f85
provide the current torch mode instead of `hasTorch` when the camera starts
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
9 deletions
lib/src/method_channel/mobile_scanner_method_channel.dart
lib/src/mobile_scanner_controller.dart
lib/src/mobile_scanner_view_attributes.dart
lib/src/web/mobile_scanner_web.dart
lib/src/method_channel/mobile_scanner_method_channel.dart
View file @
35dc61c
...
...
@@ -246,7 +246,9 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
_textureId
=
textureId
;
final
int
?
numberOfCameras
=
startResult
[
'numberOfCameras'
]
as
int
?;
final
bool
hasTorch
=
startResult
[
'torchable'
]
as
bool
?
??
false
;
final
TorchState
currentTorchState
=
TorchState
.
fromRawValue
(
startResult
[
'currentTorchState'
]
as
int
?
??
-
1
,
);
final
Map
<
Object
?,
Object
?>?
sizeInfo
=
startResult
[
'size'
]
as
Map
<
Object
?,
Object
?>?;
...
...
@@ -262,7 +264,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform {
}
return
MobileScannerViewAttributes
(
hasTorch:
hasTorch
,
currentTorchMode:
currentTorchState
,
numberOfCameras:
numberOfCameras
,
size:
size
,
);
...
...
lib/src/mobile_scanner_controller.dart
View file @
35dc61c
...
...
@@ -281,9 +281,9 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
isInitialized:
true
,
isRunning:
true
,
size:
viewAttributes
.
size
,
// If the device has a flashlight, let the platform update the torch state.
// If it does not have one, provide the unavailable state directly.
torchState:
viewAttributes
.
hasTorch
?
null
:
TorchState
.
unavailable
,
// Provide the current torch state.
// Updates are provided by the `torchStateStream`.
torchState:
viewAttributes
.
currentTorchMode
,
);
}
}
on
MobileScannerException
catch
(
error
)
{
...
...
lib/src/mobile_scanner_view_attributes.dart
View file @
35dc61c
import
'dart:ui'
;
import
'package:mobile_scanner/src/enums/torch_state.dart'
;
/// This class defines the attributes for the mobile scanner view.
class
MobileScannerViewAttributes
{
const
MobileScannerViewAttributes
({
required
this
.
hasTorch
,
required
this
.
currentTorchMode
,
this
.
numberOfCameras
,
required
this
.
size
,
});
/// Whether the current active camera has a torch.
final
bool
hasTorch
;
/// The current torch state of the active camera.
final
TorchState
currentTorchMode
;
/// The number of available cameras.
final
int
?
numberOfCameras
;
...
...
lib/src/web/mobile_scanner_web.dart
View file @
35dc61c
...
...
@@ -346,7 +346,9 @@ class MobileScannerWeb extends MobileScannerPlatform {
}
return
MobileScannerViewAttributes
(
hasTorch:
hasTorch
,
// The torch of a media stream is not available for video tracks.
// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints#instance_properties_of_video_tracks
currentTorchMode:
TorchState
.
unavailable
,
size:
_barcodeReader
?.
videoSize
??
Size
.
zero
,
);
}
catch
(
error
,
stackTrace
)
{
...
...
Please
register
or
login
to post a comment