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
Michael
2022-07-18 16:55:22 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d1b626721f2e106904d2951d34c681209d4e00af
d1b62672
1 parent
e5b455c0
Add permission callback
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
lib/src/mobile_scanner.dart
lib/src/mobile_scanner_controller.dart
lib/src/mobile_scanner.dart
View file @
d1b6267
...
...
@@ -9,6 +9,9 @@ class MobileScanner extends StatefulWidget {
/// The controller of the camera.
final
MobileScannerController
?
controller
;
/// Calls the provided [onPermissionSet] callback when the permission is set.
final
Function
(
bool
permissionGranted
)?
onPermissionSet
;
/// Function that gets called when a Barcode is detected.
///
/// [barcode] The barcode object with all information about the scanned code.
...
...
@@ -34,6 +37,7 @@ class MobileScanner extends StatefulWidget {
this
.
controller
,
this
.
fit
=
BoxFit
.
cover
,
this
.
allowDuplicates
=
false
,
this
.
onPermissionSet
,
})
:
super
(
key:
key
);
@override
...
...
@@ -48,7 +52,7 @@ class _MobileScannerState extends State<MobileScanner>
void
initState
()
{
super
.
initState
();
WidgetsBinding
.
instance
.
addObserver
(
this
);
controller
=
widget
.
controller
??
MobileScannerController
();
controller
=
widget
.
controller
??
MobileScannerController
(
onPermissionSet:
widget
.
onPermissionSet
);
}
@override
...
...
@@ -121,7 +125,7 @@ class _MobileScannerState extends State<MobileScanner>
}
}
else
{
if
(
widget
.
controller
==
null
)
{
controller
=
MobileScannerController
();
controller
=
MobileScannerController
(
onPermissionSet:
widget
.
onPermissionSet
);
}
else
if
(
oldWidget
.
controller
!=
widget
.
controller
)
{
controller
=
widget
.
controller
!;
}
...
...
lib/src/mobile_scanner_controller.dart
View file @
d1b6267
...
...
@@ -38,6 +38,7 @@ class MobileScannerController {
int
?
_controllerHashcode
;
StreamSubscription
?
events
;
Function
(
bool
permissionGranted
)?
onPermissionSet
;
final
ValueNotifier
<
MobileScannerArguments
?>
args
=
ValueNotifier
(
null
);
final
ValueNotifier
<
TorchState
>
torchState
=
ValueNotifier
(
TorchState
.
off
);
late
final
ValueNotifier
<
CameraFacing
>
cameraFacingState
;
...
...
@@ -60,6 +61,7 @@ class MobileScannerController {
this
.
ratio
,
this
.
torchEnabled
,
this
.
formats
,
this
.
onPermissionSet
,
})
{
// In case a new instance is created before calling dispose()
if
(
_controllerHashcode
!=
null
)
{
...
...
@@ -142,11 +144,14 @@ class MobileScannerController {
state
=
result
?
MobileScannerState
.
authorized
:
MobileScannerState
.
denied
;
onPermissionSet
?.
call
(
result
);
break
;
case
MobileScannerState
.
denied
:
isStarting
=
false
;
onPermissionSet
?.
call
(
false
);
throw
PlatformException
(
code:
'NO ACCESS'
);
case
MobileScannerState
.
authorized
:
onPermissionSet
?.
call
(
true
);
break
;
}
}
...
...
@@ -177,6 +182,9 @@ class MobileScannerController {
}
on
PlatformException
catch
(
error
)
{
debugPrint
(
'
${error.code}
:
${error.message}
'
);
isStarting
=
false
;
if
(
error
.
code
==
"MobileScannerWeb"
)
{
onPermissionSet
?.
call
(
false
);
}
// setAnalyzeMode(AnalyzeMode.none.index);
return
;
}
...
...
@@ -189,6 +197,8 @@ class MobileScannerController {
hasTorch
=
startResult
[
'torchable'
]
as
bool
;
if
(
kIsWeb
)
{
onPermissionSet
?.
call
(
true
);
// If we reach this line, it means camera permission has been granted
args
.
value
=
MobileScannerArguments
(
webId:
startResult
[
'ViewID'
]
as
String
?,
size:
Size
(
...
...
@@ -272,6 +282,7 @@ class MobileScannerController {
events
?.
cancel
();
events
=
null
;
_controllerHashcode
=
null
;
onPermissionSet
=
null
;
}
barcodesController
.
close
();
}
...
...
Please
register
or
login
to post a comment