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
2022-03-11 15:45:54 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d21e15d35e162092c1fb4cf15b442a4e4df7462e
d21e15d3
1 parent
2dde3cc2
feat: allow duplicates parameter
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
23 deletions
example/lib/barcode_scanner_controller.dart
example/lib/barcode_scanner_without_controller.dart
lib/src/mobile_scanner.dart
example/lib/barcode_scanner_controller.dart
View file @
d21e15d
...
...
@@ -33,16 +33,15 @@ class _BarcodeScannerWithControllerState
MobileScanner
(
controller:
controller
,
fit:
BoxFit
.
contain
,
allowDuplicates:
false
,
// controller: MobileScannerController(
// torchEnabled: true,
// facing: CameraFacing.front,
// ),
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}),
Align
(
alignment:
Alignment
.
bottomCenter
,
...
...
@@ -73,17 +72,17 @@ class _BarcodeScannerWithControllerState
onPressed:
()
=>
controller
.
toggleTorch
(),
),
IconButton
(
color:
Colors
.
white
,
icon:
isStarted
?
const
Icon
(
Icons
.
stop
)
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
color:
Colors
.
white
,
icon:
isStarted
?
const
Icon
(
Icons
.
stop
)
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
()
=>
setState
(()
{
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
=
!
isStarted
;
})),
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
=
!
isStarted
;
})),
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
200
,
...
...
example/lib/barcode_scanner_without_controller.dart
View file @
d21e15d
...
...
@@ -23,12 +23,11 @@ class _BarcodeScannerWithoutControllerState
children:
[
MobileScanner
(
fit:
BoxFit
.
contain
,
allowDuplicates:
false
,
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}),
Align
(
alignment:
Alignment
.
bottomCenter
,
...
...
lib/src/mobile_scanner.dart
View file @
d21e15d
...
...
@@ -24,9 +24,16 @@ class MobileScanner extends StatefulWidget {
/// Handles how the widget should fit the screen.
final
BoxFit
fit
;
/// Set to false if you don't want duplicate scans.
final
bool
allowDuplicates
;
/// Create a [MobileScanner] with a [controller], the [controller] must has been initialized.
const
MobileScanner
(
{
Key
?
key
,
this
.
onDetect
,
this
.
controller
,
this
.
fit
=
BoxFit
.
cover
})
{
Key
?
key
,
this
.
onDetect
,
this
.
controller
,
this
.
fit
=
BoxFit
.
cover
,
this
.
allowDuplicates
=
true
})
:
super
(
key:
key
);
@override
...
...
@@ -58,6 +65,8 @@ class _MobileScannerState extends State<MobileScanner>
}
}
String
?
lastScanned
;
@override
Widget
build
(
BuildContext
context
)
{
return
LayoutBuilder
(
builder:
(
context
,
BoxConstraints
constraints
)
{
...
...
@@ -68,8 +77,16 @@ class _MobileScannerState extends State<MobileScanner>
if
(
value
==
null
)
{
return
Container
(
color:
Colors
.
black
);
}
else
{
controller
.
barcodes
.
listen
(
(
a
)
=>
widget
.
onDetect
!(
a
,
value
as
MobileScannerArguments
));
controller
.
barcodes
.
listen
((
barcode
)
{
if
(!
widget
.
allowDuplicates
)
{
if
(
lastScanned
!=
barcode
.
rawValue
)
{
lastScanned
=
barcode
.
rawValue
;
widget
.
onDetect
!(
barcode
,
value
as
MobileScannerArguments
);
}
}
else
{
widget
.
onDetect
!(
barcode
,
value
as
MobileScannerArguments
);
}
});
return
ClipRect
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
,
...
...
Please
register
or
login
to post a comment