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-10-31 22:29:07 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e00430cba0599d540d2a0257c4236b486b5754a8
e00430cb
1 parent
aa8298a7
style: flutter format
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
45 additions
and
27 deletions
example/lib/barcode_list_scanner_controller.dart
example/lib/barcode_scanner_controller.dart
example/lib/barcode_scanner_returning_image.dart
example/lib/barcode_scanner_without_controller.dart
example/lib/main.dart
lib/src/barcode.dart
lib/src/barcode_capture.dart
lib/src/mobile_scanner.dart
lib/src/mobile_scanner_controller.dart
example/lib/barcode_list_scanner_controller.dart
View file @
e00430c
...
...
@@ -13,7 +13,6 @@ class BarcodeListScannerWithController extends StatefulWidget {
class
_BarcodeListScannerWithControllerState
extends
State
<
BarcodeListScannerWithController
>
with
SingleTickerProviderStateMixin
{
BarcodeCapture
?
barcodeCapture
;
MobileScannerController
controller
=
MobileScannerController
(
...
...
example/lib/barcode_scanner_controller.dart
View file @
e00430c
...
...
@@ -13,12 +13,10 @@ class BarcodeScannerWithController extends StatefulWidget {
class
_BarcodeScannerWithControllerState
extends
State
<
BarcodeScannerWithController
>
with
SingleTickerProviderStateMixin
{
BarcodeCapture
?
barcode
;
MobileScannerController
controller
=
MobileScannerController
(
torchEnabled:
true
,
detectionSpeed:
DetectionSpeed
.
unrestricted
torchEnabled:
true
,
detectionSpeed:
DetectionSpeed
.
unrestricted
,
// formats: [BarcodeFormat.qrCode]
// facing: CameraFacing.front,
);
...
...
@@ -101,7 +99,8 @@ class _BarcodeScannerWithControllerState
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
barcode
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
...
...
example/lib/barcode_scanner_returning_image.dart
View file @
e00430c
import
'dart:math'
;
import
'dart:typed_data'
;
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
...
...
@@ -27,7 +26,6 @@ class _BarcodeScannerReturningImageState
bool
isStarted
=
true
;
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
...
...
@@ -42,14 +40,21 @@ class _BarcodeScannerReturningImageState
height:
0.33
*
MediaQuery
.
of
(
context
).
size
.
height
,
child:
barcode
?.
image
!=
null
?
Transform
.
rotate
(
angle:
90
*
pi
/
180
,
angle:
90
*
pi
/
180
,
child:
Image
(
gaplessPlayback:
true
,
image:
MemoryImage
(
barcode
!.
image
!),
fit:
BoxFit
.
contain
,
),
)
:
Container
(
color:
Colors
.
white
,
child:
const
Center
(
child:
Text
(
'Your scanned barcode will appear here!'
))),
:
Container
(
color:
Colors
.
white
,
child:
const
Center
(
child:
Text
(
'Your scanned barcode will appear here!'
,
),
),
),
),
Container
(
height:
0.66
*
MediaQuery
.
of
(
context
).
size
.
height
,
...
...
@@ -81,7 +86,9 @@ class _BarcodeScannerReturningImageState
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
Container
(
color:
arguments
!=
null
&&
!
arguments
!.
hasTorch
?
Colors
.
red
:
Colors
.
white
,
color:
arguments
!=
null
&&
!
arguments
!.
hasTorch
?
Colors
.
red
:
Colors
.
white
,
child:
IconButton
(
// color: ,
icon:
ValueListenableBuilder
(
...
...
@@ -118,7 +125,9 @@ class _BarcodeScannerReturningImageState
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
()
=>
setState
(()
{
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
?
controller
.
stop
()
:
controller
.
start
();
isStarted
=
!
isStarted
;
}),
),
...
...
@@ -128,7 +137,8 @@ class _BarcodeScannerReturningImageState
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
barcode
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
...
...
example/lib/barcode_scanner_without_controller.dart
View file @
e00430c
...
...
@@ -46,7 +46,8 @@ class _BarcodeScannerWithoutControllerState
height:
50
,
child:
FittedBox
(
child:
Text
(
capture
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
capture
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
...
...
example/lib/main.dart
View file @
e00430c
...
...
@@ -23,7 +23,8 @@ class MyHome extends StatelessWidget {
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeListScannerWithController
(),
builder:
(
context
)
=>
const
BarcodeListScannerWithController
(),
),
);
},
...
...
lib/src/barcode.dart
View file @
e00430c
lib/src/barcode_capture.dart
View file @
e00430c
...
...
@@ -10,5 +10,4 @@ class BarcodeCapture {
required
this
.
barcodes
,
this
.
image
,
});
}
...
...
lib/src/mobile_scanner.dart
View file @
e00430c
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/src/barcode_capture.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_arguments.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_controller.dart'
;
import
'package:mobile_scanner/src/barcode_capture.dart'
;
/// A widget showing a live camera preview.
class
MobileScanner
extends
StatefulWidget
{
...
...
@@ -16,8 +16,7 @@ class MobileScanner extends StatefulWidget {
///
/// [barcode] The barcode object with all information about the scanned code.
/// [startArguments] Information about the state of the MobileScanner widget
final
Function
(
BarcodeCapture
capture
,
MobileScannerArguments
?
arguments
)
final
Function
(
BarcodeCapture
capture
,
MobileScannerArguments
?
arguments
)
onDetect
;
/// Handles how the widget should fit the screen.
...
...
@@ -59,7 +58,9 @@ class _MobileScannerState extends State<MobileScanner>
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
switch
(
state
)
{
case
AppLifecycleState
.
resumed
:
if
(!
controller
.
isStarting
&&
widget
.
autoResume
&&
_lastState
!=
AppLifecycleState
.
inactive
)
controller
.
start
();
if
(!
controller
.
isStarting
&&
widget
.
autoResume
&&
_lastState
!=
AppLifecycleState
.
inactive
)
controller
.
start
();
break
;
case
AppLifecycleState
.
paused
:
case
AppLifecycleState
.
detached
:
...
...
lib/src/mobile_scanner_controller.dart
View file @
e00430c
...
...
@@ -5,7 +5,6 @@ import 'package:flutter/cupertino.dart';
import
'package:flutter/foundation.dart'
;
import
'package:flutter/services.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner/src/barcode_capture.dart'
;
import
'package:mobile_scanner/src/barcode_utility.dart'
;
import
'package:mobile_scanner/src/mobile_scanner_exception.dart'
;
...
...
@@ -79,7 +78,8 @@ class MobileScannerController {
late
StreamSubscription
events
;
/// A notifier that provides several arguments about the MobileScanner
final
ValueNotifier
<
MobileScannerArguments
?>
startArguments
=
ValueNotifier
(
null
);
final
ValueNotifier
<
MobileScannerArguments
?>
startArguments
=
ValueNotifier
(
null
);
/// A notifier that provides the state of the Torch (Flash)
final
ValueNotifier
<
TorchState
>
torchState
=
ValueNotifier
(
TorchState
.
off
);
...
...
@@ -167,7 +167,8 @@ class MobileScannerController {
if
(
startResult
==
null
)
{
isStarting
=
false
;
throw
MobileScannerException
(
'Failed to start mobileScanner, no response from platform side'
);
'Failed to start mobileScanner, no response from platform side'
,
);
}
_hasTorch
=
startResult
[
'torchable'
]
as
bool
?
??
false
;
...
...
@@ -210,7 +211,8 @@ class MobileScannerController {
Future
<
void
>
toggleTorch
()
async
{
if
(
_hasTorch
==
null
)
{
throw
MobileScannerException
(
'Cannot toggle torch if start() has never been called'
);
'Cannot toggle torch if start() has never been called'
,
);
}
else
if
(!
_hasTorch
!)
{
throw
MobileScannerException
(
'Device has no torch'
);
}
...
...
@@ -272,10 +274,12 @@ class MobileScannerController {
final
parsed
=
(
data
as
List
)
.
map
((
value
)
=>
Barcode
.
fromNative
(
value
as
Map
))
.
toList
();
_barcodesController
.
add
(
BarcodeCapture
(
_barcodesController
.
add
(
BarcodeCapture
(
barcodes:
parsed
,
image:
event
[
'image'
]
as
Uint8List
,
));
),
);
break
;
case
'barcodeMac'
:
_barcodesController
.
add
(
...
...
@@ -289,11 +293,15 @@ class MobileScannerController {
);
break
;
case
'barcodeWeb'
:
_barcodesController
.
add
(
BarcodeCapture
(
barcodes:
[
_barcodesController
.
add
(
BarcodeCapture
(
barcodes:
[
Barcode
(
rawValue:
data
as
String
?,
)
]));
],
),
);
break
;
case
'error'
:
throw
MobileScannerException
(
data
as
String
);
...
...
Please
register
or
login
to post a comment