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-10-21 14:59:00 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c159cd7060f079fa620f7f24e7afbad4d7a9f95c
c159cd70
1 parent
5c742696
remove duplicate value notifier; update try catch in start camera; format FAB button
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
31 deletions
example/lib/mobile_scanner_overlay.dart
example/lib/mobile_scanner_overlay.dart
View file @
c159cd7
...
...
@@ -12,8 +12,6 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
String
overlayText
=
"Please scan QR Code"
;
bool
camStarted
=
false
;
final
ValueNotifier
<
bool
>
torchStateNotifier
=
ValueNotifier
<
bool
>(
false
);
final
MobileScannerController
controller
=
MobileScannerController
(
formats:
const
[
BarcodeFormat
.
qrCode
],
autoStart:
false
,
...
...
@@ -26,19 +24,26 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
}
void
startCamera
()
{
try
{
setState
(()
{
camStarted
=
!
camStarted
;
controller
.
start
();
});
}
on
Exception
catch
(
e
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
(
'Something went wrong!
$e
'
),
backgroundColor:
Colors
.
red
,
),
);
if
(
camStarted
)
{
return
;
}
controller
.
start
().
then
((
_
)
{
if
(
mounted
)
{
setState
(()
{
camStarted
=
true
;
});
}
}).
catchError
((
Object
error
,
StackTrace
stackTrace
)
{
if
(
mounted
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
(
'Something went wrong!
$error
'
),
backgroundColor:
Colors
.
red
,
),
);
}
});
}
void
onBarcodeDetect
(
BarcodeCapture
barcodeCapture
)
{
...
...
@@ -112,20 +117,25 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
ValueListenableBuilder
<
bool
>(
valueListenable:
torchStateNotifier
,
builder:
(
context
,
isTorchOn
,
child
)
{
ValueListenableBuilder
<
TorchState
>(
valueListenable:
controller
.
torchState
,
builder:
(
context
,
value
,
child
)
{
final
Color
iconColor
;
switch
(
value
)
{
case
TorchState
.
off
:
iconColor
=
Colors
.
black
;
break
;
case
TorchState
.
on
:
iconColor
=
Colors
.
yellow
;
break
;
}
return
IconButton
(
onPressed:
()
{
controller
.
toggleTorch
();
torchStateNotifier
.
value
=
!
torchStateNotifier
.
value
;
},
onPressed:
()
=>
controller
.
toggleTorch
(),
icon:
Icon
(
Icons
.
flashlight_on
,
color:
isTorchOn
?
Colors
.
yellow
:
Colors
.
black
,
color:
iconColor
,
),
);
},
...
...
@@ -153,12 +163,8 @@ class _BarcodeScannerWithOverlayState extends State<BarcodeScannerWithOverlay> {
floatingActionButton:
camStarted
?
null
:
FloatingActionButton
(
child:
const
Icon
(
Icons
.
camera_alt
,
),
onPressed:
()
{
startCamera
();
},
onPressed:
startCamera
,
child:
const
Icon
(
Icons
.
camera_alt
),
),
);
}
...
...
Please
register
or
login
to post a comment