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-22 12:19:45 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0f4754905138f629fd630c9fa01fb64ef9b89e85
0f475490
1 parent
d6644baa
add base for the new barcode reader
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
lib/src/web/barcode_reader.dart
lib/src/web/barcode_reader.dart
0 → 100644
View file @
0f47549
import
'dart:async'
;
import
'dart:js_interop'
;
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:web/web.dart'
;
/// This class represents the base interface for a barcode reader implementation.
abstract
class
BarcodeReader
{
const
BarcodeReader
();
/// The id for the script tag that loads the barcode library.
///
/// If a script tag with this id already exists,
/// the library will not be loaded again.
String
get
scriptId
=>
'mobile-scanner-barcode-reader'
;
/// The script url for the barcode library.
String
get
scriptUrl
;
/// Load the barcode reader library.
///
/// Does nothing if the library is already loaded.
Future
<
void
>
maybeLoadLibrary
()
async
{
// Script already exists.
if
(
document
.
querySelector
(
'script#
$scriptId
'
)
!=
null
)
{
return
;
}
final
Completer
<
void
>
completer
=
Completer
();
final
HTMLScriptElement
script
=
(
document
.
createElement
(
'script'
)
as
HTMLScriptElement
)
..
id
=
scriptId
..
async
=
true
..
defer
=
false
..
type
=
'application/javascript'
..
lang
=
'javascript'
..
crossOrigin
=
'anonymous'
..
src
=
scriptUrl
..
onload
=
allowInterop
((
JSAny
_
)
{
if
(!
completer
.
isCompleted
)
{
completer
.
complete
();
}
}).
toJS
;
script
.
onerror
=
allowInterop
((
JSAny
_
)
{
if
(!
completer
.
isCompleted
)
{
// Remove the script if it did not load.
document
.
head
!.
removeChild
(
script
);
completer
.
completeError
(
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
genericError
,
errorDetails:
MobileScannerErrorDetails
(
message:
'Could not load the BarcodeReader script due to a network error.'
,
),
),
);
}
}).
toJS
;
document
.
head
!.
appendChild
(
script
);
await
completer
.
future
;
}
/// Set the flashlight state for the device.
Future
<
void
>
setTorchState
(
TorchState
torchState
)
{
throw
UnimplementedError
(
'setTorchState() has not been implemented.'
);
}
/// Stop the barcode reader and dispose of the video stream.
Future
<
void
>
stop
()
{
throw
UnimplementedError
(
'stop() has not been implemented.'
);
}
}
...
...
Please
register
or
login
to post a comment