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:03:34 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2dde3cc2da600f0611ba95f8c100e277509f8d38
2dde3cc2
1 parent
08c0b8d6
bug: fixed pop() not working
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
155 additions
and
159 deletions
example/lib/barcode_scanner_controller.dart
example/lib/barcode_scanner_without_controller.dart
example/lib/barcode_scanner_controller.dart
View file @
2dde3cc
...
...
@@ -25,132 +25,130 @@ class _BarcodeScannerWithControllerState
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
Scaffold
(
backgroundColor:
Colors
.
black
,
body:
Builder
(
builder:
(
context
)
{
return
Stack
(
children:
[
MobileScanner
(
controller:
controller
,
fit:
BoxFit
.
contain
,
// controller: MobileScannerController(
// torchEnabled: true,
// facing: CameraFacing.front,
// ),
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}
}),
Align
(
return
Scaffold
(
backgroundColor:
Colors
.
black
,
body:
Builder
(
builder:
(
context
)
{
return
Stack
(
children:
[
MobileScanner
(
controller:
controller
,
fit:
BoxFit
.
contain
,
// controller: MobileScannerController(
// torchEnabled: true,
// facing: CameraFacing.front,
// ),
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}
}),
Align
(
alignment:
Alignment
.
bottomCenter
,
child:
Container
(
alignment:
Alignment
.
bottomCenter
,
child:
Container
(
alignment:
Alignment
.
bottomCenter
,
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
child:
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
(
valueListenable:
controller
.
torchState
,
builder:
(
context
,
state
,
child
)
{
switch
(
state
as
TorchState
)
{
case
TorchState
.
off
:
return
const
Icon
(
Icons
.
flash_off
,
color:
Colors
.
grey
);
case
TorchState
.
on
:
return
const
Icon
(
Icons
.
flash_on
,
color:
Colors
.
yellow
);
}
},
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
toggleTorch
(),
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
child:
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
(
valueListenable:
controller
.
torchState
,
builder:
(
context
,
state
,
child
)
{
switch
(
state
as
TorchState
)
{
case
TorchState
.
off
:
return
const
Icon
(
Icons
.
flash_off
,
color:
Colors
.
grey
);
case
TorchState
.
on
:
return
const
Icon
(
Icons
.
flash_on
,
color:
Colors
.
yellow
);
}
},
),
IconButton
(
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
;
})),
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
200
,
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headline4
!
.
copyWith
(
color:
Colors
.
white
),
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
toggleTorch
(),
),
IconButton
(
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
;
})),
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
200
,
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headline4
!
.
copyWith
(
color:
Colors
.
white
),
),
),
),
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
(
valueListenable:
controller
.
cameraFacingState
,
builder:
(
context
,
state
,
child
)
{
switch
(
state
as
CameraFacing
)
{
case
CameraFacing
.
front
:
return
const
Icon
(
Icons
.
camera_front
);
case
CameraFacing
.
back
:
return
const
Icon
(
Icons
.
camera_rear
);
}
},
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
switchCamera
(),
),
IconButton
(
color:
Colors
.
white
,
icon:
const
Icon
(
Icons
.
image
),
iconSize:
32.0
,
onPressed:
()
async
{
final
ImagePicker
_picker
=
ImagePicker
();
// Pick an image
final
XFile
?
image
=
await
_picker
.
pickImage
(
source
:
ImageSource
.
gallery
);
if
(
image
!=
null
)
{
if
(
await
controller
.
analyzeImage
(
image
.
path
))
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'Barcode found!'
),
backgroundColor:
Colors
.
green
,
));
}
else
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'No barcode found!'
),
backgroundColor:
Colors
.
red
,
));
}
),
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
(
valueListenable:
controller
.
cameraFacingState
,
builder:
(
context
,
state
,
child
)
{
switch
(
state
as
CameraFacing
)
{
case
CameraFacing
.
front
:
return
const
Icon
(
Icons
.
camera_front
);
case
CameraFacing
.
back
:
return
const
Icon
(
Icons
.
camera_rear
);
}
},
),
],
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
switchCamera
(),
),
IconButton
(
color:
Colors
.
white
,
icon:
const
Icon
(
Icons
.
image
),
iconSize:
32.0
,
onPressed:
()
async
{
final
ImagePicker
_picker
=
ImagePicker
();
// Pick an image
final
XFile
?
image
=
await
_picker
.
pickImage
(
source
:
ImageSource
.
gallery
);
if
(
image
!=
null
)
{
if
(
await
controller
.
analyzeImage
(
image
.
path
))
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'Barcode found!'
),
backgroundColor:
Colors
.
green
,
));
}
else
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'No barcode found!'
),
backgroundColor:
Colors
.
red
,
));
}
}
},
),
],
),
),
],
);
}),
),
),
],
);
}),
);
}
}
...
...
example/lib/barcode_scanner_without_controller.dart
View file @
2dde3cc
...
...
@@ -16,55 +16,53 @@ class _BarcodeScannerWithoutControllerState
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
home:
Scaffold
(
backgroundColor:
Colors
.
black
,
body:
Builder
(
builder:
(
context
)
{
return
Stack
(
children:
[
MobileScanner
(
fit:
BoxFit
.
contain
,
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}
}),
Align
(
return
Scaffold
(
backgroundColor:
Colors
.
black
,
body:
Builder
(
builder:
(
context
)
{
return
Stack
(
children:
[
MobileScanner
(
fit:
BoxFit
.
contain
,
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
setState
(()
{
this
.
barcode
=
barcode
.
rawValue
;
});
}
}),
Align
(
alignment:
Alignment
.
bottomCenter
,
child:
Container
(
alignment:
Alignment
.
bottomCenter
,
child:
Container
(
alignment:
Alignment
.
bottomCenter
,
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
child:
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
120
,
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headline4
!
.
copyWith
(
color:
Colors
.
white
),
),
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
child:
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
120
,
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headline4
!
.
copyWith
(
color:
Colors
.
white
),
),
),
),
],
),
),
],
),
),
],
);
}),
),
),
],
);
}),
);
}
}
...
...
Please
register
or
login
to post a comment