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
Julian Steenbakker
2025-04-17 23:47:27 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7f457936e6232257f5c50e6abdcd6af8ad420c7d
7f457936
1 parent
40e3ee6b
fix: move subscription.cancel to async dispose, move removeObserver
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
lib/src/mobile_scanner.dart
lib/src/mobile_scanner.dart
View file @
7f45793
...
...
@@ -256,7 +256,7 @@ class _MobileScannerState extends State<MobileScanner>
StreamSubscription
?
_subscription
;
Future
<
void
>
init
Controll
er
()
async
{
Future
<
void
>
init
MobileScann
er
()
async
{
// TODO: This will be fixed in another PR
// If debug mode is enabled, stop the controller first before starting it.
// If a hot-restart is initiated, the controller won't be stopped, and because
...
...
@@ -284,7 +284,10 @@ class _MobileScannerState extends State<MobileScanner>
}
}
Future
<
void
>
disposeCamera
()
async
{
Future
<
void
>
disposeMobileScanner
()
async
{
await
_subscription
?.
cancel
();
WidgetsBinding
.
instance
.
removeObserver
(
this
);
if
(
controller
.
autoStart
)
{
await
controller
.
stop
();
}
...
...
@@ -292,7 +295,6 @@ class _MobileScannerState extends State<MobileScanner>
// Dispose default controller if not provided by user
if
(
widget
.
controller
==
null
)
{
await
controller
.
dispose
();
WidgetsBinding
.
instance
.
removeObserver
(
this
);
}
}
...
...
@@ -300,19 +302,13 @@ class _MobileScannerState extends State<MobileScanner>
void
initState
()
{
super
.
initState
();
controller
=
widget
.
controller
??
MobileScannerController
();
init
Controll
er
();
init
MobileScann
er
();
}
@override
void
dispose
()
{
if
(
_subscription
!=
null
)
{
_subscription
!.
cancel
();
_subscription
=
null
;
}
disposeCamera
();
super
.
dispose
();
disposeMobileScanner
();
}
@override
...
...
@@ -336,7 +332,6 @@ class _MobileScannerState extends State<MobileScanner>
unawaited
(
controller
.
start
());
case
AppLifecycleState
.
inactive
:
unawaited
(
_subscription
?.
cancel
());
_subscription
=
null
;
unawaited
(
controller
.
stop
());
}
}
...
...
Please
register
or
login
to post a comment