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-12-07 16:09:23 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
26c6ba80ef7d2cde313b0d45790b9c47a1887040
26c6ba80
1 parent
019526a3
add hasTorch & setTorchState to the barcode reader interface instead
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
lib/src/web/barcode_reader.dart
lib/src/web/mobile_scanner_web.dart
lib/src/web/barcode_reader.dart
View file @
26c6ba8
...
...
@@ -4,19 +4,16 @@ import 'dart:ui';
import
'package:js/js.dart'
;
import
'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'
;
import
'package:mobile_scanner/src/enums/torch_state.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_exception.dart'
;
import
'package:mobile_scanner/src/objects/barcode_capture.dart'
;
import
'package:mobile_scanner/src/objects/start_options.dart'
;
import
'package:mobile_scanner/src/web/flashlight_delegate.dart'
;
import
'package:web/web.dart'
;
/// This class represents the base interface for a barcode reader implementation.
abstract
class
BarcodeReader
{
const
BarcodeReader
();
/// Get the flashlight delegate for the barcode reader.
FlashlightDelegate
get
flashlightDelegate
=>
const
FlashlightDelegate
();
/// Whether the scanner is currently scanning for barcodes.
bool
get
isScanning
{
throw
UnimplementedError
(
'isScanning has not been implemented.'
);
...
...
@@ -45,6 +42,11 @@ abstract class BarcodeReader {
throw
UnimplementedError
(
'detectBarcodes() has not been implemented.'
);
}
/// Check whether the active camera has a flashlight.
Future
<
bool
>
hasTorch
()
{
throw
UnimplementedError
(
'hasTorch() has not been implemented.'
);
}
/// Load the barcode reader library.
///
/// Does nothing if the library is already loaded.
...
...
@@ -93,6 +95,11 @@ abstract class BarcodeReader {
await
completer
.
future
;
}
/// Set the torch state for the active camera to the given [value].
Future
<
void
>
setTorchState
(
TorchState
value
)
{
throw
UnimplementedError
(
'setTorchState() has not been implemented.'
);
}
/// Start the barcode reader and initialize the video stream.
///
/// The [options] are used to configure the barcode reader.
...
...
lib/src/web/mobile_scanner_web.dart
View file @
26c6ba8
...
...
@@ -115,12 +115,10 @@ class MobileScannerWeb extends MobileScannerPlatform {
_barcodesController
.
add
(
barcode
);
});
final
bool
hasTorch
=
_barcodeReader
.
hasTorch
;
final
bool
hasTorch
=
await
_barcodeReader
.
hasTorch
()
;
if
(
hasTorch
&&
startOptions
.
torchEnabled
)
{
await
_barcodeReader
.
setTorchState
(
TorchState
.
on
).
catchError
((
_
)
{
// If the torch could not be turned on, continue the camera session anyway.
});
await
_barcodeReader
.
setTorchState
(
TorchState
.
on
);
}
return
MobileScannerViewAttributes
(
...
...
Please
register
or
login
to post a comment