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
Elias Andualem
2022-02-18 18:57:37 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2872265f237afac12a22927d4d122684e1fe0783
2872265f
1 parent
78cc11d6
fix: Handle all cases when a controller should be initialized and disposed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
lib/src/mobile_scanner.dart
lib/src/mobile_scanner.dart
View file @
2872265
...
...
@@ -26,9 +26,12 @@ class MobileScanner extends StatefulWidget {
final
BoxFit
fit
;
/// Create a [MobileScanner] with a [controller], the [controller] must has been initialized.
const
MobileScanner
(
{
Key
?
key
,
this
.
onDetect
,
this
.
controller
,
this
.
fit
=
BoxFit
.
cover
})
:
assert
((
controller
!=
null
)),
const
MobileScanner
({
Key
?
key
,
this
.
onDetect
,
this
.
controller
,
this
.
fit
=
BoxFit
.
cover
,
})
:
assert
((
controller
!=
null
)),
super
(
key:
key
);
@override
...
...
@@ -43,11 +46,7 @@ class _MobileScannerState extends State<MobileScanner>
@override
void
initState
()
{
super
.
initState
();
if
(
widget
.
controller
==
null
)
{
controller
=
MobileScannerController
();
}
else
{
controller
=
widget
.
controller
!;
}
controller
=
widget
.
controller
??
MobileScannerController
();
}
@override
...
...
@@ -97,8 +96,25 @@ class _MobileScannerState extends State<MobileScanner>
}
@override
void
dispose
()
{
void
didUpdateWidget
(
covariant
MobileScanner
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
oldWidget
.
controller
==
null
)
{
if
(
widget
.
controller
!=
null
)
{
controller
.
dispose
();
controller
=
widget
.
controller
!;
}
}
else
{
if
(
widget
.
controller
==
null
)
{
controller
=
MobileScannerController
();
}
else
if
(
oldWidget
.
controller
!=
widget
.
controller
)
{
controller
=
widget
.
controller
!;
}
}
}
@override
void
dispose
()
{
if
(
widget
.
controller
==
null
)
controller
.
dispose
();
super
.
dispose
();
}
}
...
...
Please
register
or
login
to post a comment