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 17:19:50 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3bb3383e541baacb54251b721fcc081406d4eee1
3bb3383e
1 parent
86e8e952
add helper to check disposal
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
lib/src/mobile_scanner_controller.dart
lib/src/mobile_scanner_controller.dart
View file @
3bb3383
...
...
@@ -94,6 +94,28 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
/// Get the stream of scanned barcodes.
Stream
<
BarcodeCapture
>
get
barcodes
=>
_barcodesController
.
stream
;
bool
_isDisposed
=
false
;
void
_throwIfNotInitialized
()
{
if
(!
value
.
isInitialized
)
{
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
controllerUninitialized
,
errorDetails:
MobileScannerErrorDetails
(
message:
'The MobileScannerController has not been initialized.'
,
),
);
}
if
(
_isDisposed
)
{
throw
const
MobileScannerException
(
errorCode:
MobileScannerErrorCode
.
controllerDisposed
,
errorDetails:
MobileScannerErrorDetails
(
message:
'The MobileScannerController was used after it has been disposed.'
,
),
);
}
}
/// Analyze an image file.
///
/// The [path] points to a file on the device.
...
...
@@ -166,9 +188,14 @@ class MobileScannerController extends ValueNotifier<MobileScannerState> {
@override
Future
<
void
>
dispose
()
async
{
if
(
_isDisposed
)
{
return
;
}
await
MobileScannerPlatform
.
instance
.
dispose
();
unawaited
(
_barcodesController
.
close
());
_isDisposed
=
true
;
super
.
dispose
();
}
}
...
...
Please
register
or
login
to post a comment