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-02-16 09:35:31 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
24888522d87c15d62bde6fa69f38e100a2d14bf3
24888522
1 parent
e893f84f
style: flutter format
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
63 deletions
example/lib/main.dart
example/lib/mobile_scanner_overlay.dart
lib/mobile_scanner.dart
lib/src/mobile_scanner.dart
lib/src/mobile_scanner_arguments.dart
lib/src/mobile_scanner_controller.dart
test/mobile_scanner_test.dart
example/lib/main.dart
View file @
2488852
...
...
@@ -18,8 +18,10 @@ class _AnalyzeViewState extends State<AnalyzeView>
with
SingleTickerProviderStateMixin
{
String
?
barcode
;
MobileScannerController
controller
=
MobileScannerController
(
torchEnabled:
true
,
facing:
CameraFacing
.
front
,);
MobileScannerController
controller
=
MobileScannerController
(
torchEnabled:
true
,
facing:
CameraFacing
.
front
,
);
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -30,7 +32,7 @@ class _AnalyzeViewState extends State<AnalyzeView>
return
Stack
(
children:
[
MobileScanner
(
controller:
controller
,
controller:
controller
,
fit:
BoxFit
.
contain
,
// controller: MobileScannerController(
// torchEnabled: true,
...
...
@@ -55,20 +57,22 @@ class _AnalyzeViewState extends State<AnalyzeView>
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
(),
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
(),
),
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
120
,
...
...
example/lib/mobile_scanner_overlay.dart
View file @
2488852
...
...
@@ -30,40 +30,41 @@ class _AnalyzeViewState extends State<AnalyzeView>
return
Stack
(
children:
[
MobileScanner
(
// fitScreen: false,
// fitScreen: false,
// controller: cameraController,
onDetect:
(
barcode
,
args
)
{
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
this
.
barcode
=
barcode
.
rawValue
;
if
(
barcode
.
corners
!=
null
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
(
'
${barcode.rawValue}
'
),
duration:
const
Duration
(
milliseconds:
200
),
animation:
null
,
));
setState
(()
{
final
List
<
Offset
>
points
=
[];
double
factorWidth
=
args
.
size
.
width
/
520
;
// double factorHeight = wanted / args.size.height;
final
size
=
MediaQuery
.
of
(
context
).
devicePixelRatio
;
debugPrint
(
'Size:
${barcode.corners}
'
);
for
(
var
point
in
barcode
.
corners
!)
{
final
adjustedWith
=
point
.
dx
;
final
adjustedHeight
=
point
.
dy
;
points
.
add
(
Offset
(
adjustedWith
/
size
,
adjustedHeight
/
size
));
// points.add(Offset((point.dx ) / size,
// (point.dy) / size));
// final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;
// final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;
// points.add(Offset((point.dx + differenceWidth) / size,
// (point.dy + differenceHeight) / size));
}
this
.
points
=
points
;
});
if
(
this
.
barcode
!=
barcode
.
rawValue
)
{
this
.
barcode
=
barcode
.
rawValue
;
if
(
barcode
.
corners
!=
null
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
(
'
${barcode.rawValue}
'
),
duration:
const
Duration
(
milliseconds:
200
),
animation:
null
,
));
setState
(()
{
final
List
<
Offset
>
points
=
[];
double
factorWidth
=
args
.
size
.
width
/
520
;
// double factorHeight = wanted / args.size.height;
final
size
=
MediaQuery
.
of
(
context
).
devicePixelRatio
;
debugPrint
(
'Size:
${barcode.corners}
'
);
for
(
var
point
in
barcode
.
corners
!)
{
final
adjustedWith
=
point
.
dx
;
final
adjustedHeight
=
point
.
dy
;
points
.
add
(
Offset
(
adjustedWith
/
size
,
adjustedHeight
/
size
));
// points.add(Offset((point.dx ) / size,
// (point.dy) / size));
// final differenceWidth = (args.wantedSize!.width - args.size.width) / 2;
// final differenceHeight = (args.wantedSize!.height - args.size.height) / 2;
// points.add(Offset((point.dx + differenceWidth) / size,
// (point.dy + differenceHeight) / size));
}
}
// Default 640 x480
}),
this
.
points
=
points
;
});
}
}
// Default 640 x480
}),
CustomPaint
(
painter:
OpenPainter
(
points
),
),
...
...
lib/mobile_scanner.dart
View file @
2488852
...
...
@@ -2,4 +2,4 @@ library mobile_scanner;
export
'src/mobile_scanner.dart'
;
export
'src/mobile_scanner_controller.dart'
;
export
'src/objects/barcode.dart'
;
\ No newline at end of file
export
'src/objects/barcode.dart'
;
...
...
lib/src/mobile_scanner.dart
View file @
2488852
...
...
@@ -3,10 +3,7 @@ import 'package:mobile_scanner/mobile_scanner.dart';
import
'mobile_scanner_arguments.dart'
;
enum
Ratio
{
ratio_4_3
,
ratio_16_9
}
enum
Ratio
{
ratio_4_3
,
ratio_16_9
}
/// A widget showing a live camera preview.
class
MobileScanner
extends
StatefulWidget
{
...
...
@@ -18,7 +15,8 @@ class MobileScanner extends StatefulWidget {
/// 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
)),
super
(
key:
key
);
:
assert
((
controller
!=
null
)),
super
(
key:
key
);
@override
State
<
MobileScanner
>
createState
()
=>
_MobileScannerState
();
...
...
@@ -91,4 +89,4 @@ class _MobileScannerState extends State<MobileScanner>
controller
.
dispose
();
super
.
dispose
();
}
}
\ No newline at end of file
}
...
...
lib/src/mobile_scanner_arguments.dart
View file @
2488852
...
...
@@ -11,5 +11,6 @@ class MobileScannerArguments {
final
bool
hasTorch
;
/// Create a [MobileScannerArguments].
MobileScannerArguments
({
required
this
.
textureId
,
required
this
.
size
,
required
this
.
hasTorch
});
MobileScannerArguments
(
{
required
this
.
textureId
,
required
this
.
size
,
required
this
.
hasTorch
});
}
...
...
lib/src/mobile_scanner_controller.dart
View file @
2488852
...
...
@@ -38,7 +38,6 @@ class MobileScannerController {
int
?
_controllerHashcode
;
StreamSubscription
?
events
;
final
ValueNotifier
<
MobileScannerArguments
?>
args
=
ValueNotifier
(
null
);
final
ValueNotifier
<
TorchState
>
torchState
=
ValueNotifier
(
TorchState
.
off
);
late
final
ValueNotifier
<
CameraFacing
>
cameraFacingState
;
...
...
@@ -107,7 +106,8 @@ class MobileScannerController {
setAnalyzeMode
(
AnalyzeMode
.
barcode
.
index
);
// Check authorization status
MobileScannerState
state
=
MobileScannerState
.
values
[
await
methodChannel
.
invokeMethod
(
'state'
)];
MobileScannerState
state
=
MobileScannerState
.
values
[
await
methodChannel
.
invokeMethod
(
'state'
)];
switch
(
state
)
{
case
MobileScannerState
.
undetermined
:
final
bool
result
=
await
methodChannel
.
invokeMethod
(
'request'
);
...
...
@@ -129,13 +129,17 @@ class MobileScannerController {
if
(
torchEnabled
!=
null
)
arguments
[
'torch'
]
=
torchEnabled
;
// Start the camera with arguments
final
Map
<
String
,
dynamic
>?
startResult
=
await
methodChannel
.
invokeMapMethod
<
String
,
dynamic
>(
'start'
,
arguments
);
final
Map
<
String
,
dynamic
>?
startResult
=
await
methodChannel
.
invokeMapMethod
<
String
,
dynamic
>(
'start'
,
arguments
);
if
(
startResult
==
null
)
throw
PlatformException
(
code:
'INITIALIZATION ERROR'
);
if
(
startResult
==
null
)
throw
PlatformException
(
code:
'INITIALIZATION ERROR'
);
hasTorch
=
startResult
[
'torchable'
];
args
.
value
=
MobileScannerArguments
(
textureId:
startResult
[
'textureId'
],
size:
toSize
(
startResult
[
'size'
]),
hasTorch:
hasTorch
);
args
.
value
=
MobileScannerArguments
(
textureId:
startResult
[
'textureId'
],
size:
toSize
(
startResult
[
'size'
]),
hasTorch:
hasTorch
);
}
Future
<
void
>
stop
()
async
=>
await
methodChannel
.
invokeMethod
(
'stop'
);
...
...
@@ -157,7 +161,8 @@ class MobileScannerController {
Future
<
void
>
switchCamera
()
async
{
ensure
(
'switchCamera'
);
await
stop
();
facing
=
facing
==
CameraFacing
.
back
?
CameraFacing
.
front
:
CameraFacing
.
back
;
facing
=
facing
==
CameraFacing
.
back
?
CameraFacing
.
front
:
CameraFacing
.
back
;
start
();
}
...
...
test/mobile_scanner_test.dart
View file @
2488852
...
...
@@ -16,5 +16,4 @@ void main() {
tearDown
(()
{
channel
.
setMockMethodCallHandler
(
null
);
});
}
...
...
Please
register
or
login
to post a comment