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-11-09 14:18:59 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cb3364b6a6466e5f21ce0d63030e79d0943c72b1
cb3364b6
1 parent
b551840c
fix the return image sample
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
101 deletions
example/lib/barcode_scanner_returning_image.dart
example/lib/barcode_scanner_returning_image.dart
View file @
cb3364b
...
...
@@ -2,6 +2,7 @@ import 'dart:math';
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanner_button_widgets.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
class
BarcodeScannerReturningImage
extends
StatefulWidget
{
...
...
@@ -13,11 +14,7 @@ class BarcodeScannerReturningImage extends StatefulWidget {
}
class
_BarcodeScannerReturningImageState
extends
State
<
BarcodeScannerReturningImage
>
with
SingleTickerProviderStateMixin
{
BarcodeCapture
?
barcode
;
// MobileScannerArguments? arguments;
extends
State
<
BarcodeScannerReturningImage
>
{
final
MobileScannerController
controller
=
MobileScannerController
(
torchEnabled:
true
,
// formats: [BarcodeFormat.qrCode]
...
...
@@ -27,26 +24,10 @@ class _BarcodeScannerReturningImageState
returnImage:
true
,
);
bool
isStarted
=
true
;
void
_startOrStop
()
{
try
{
if
(
isStarted
)
{
controller
.
stop
();
}
else
{
controller
.
start
();
}
setState
(()
{
isStarted
=
!
isStarted
;
});
}
on
Exception
catch
(
e
)
{
ScaffoldMessenger
.
of
(
context
).
showSnackBar
(
SnackBar
(
content:
Text
(
'Something went wrong!
$e
'
),
backgroundColor:
Colors
.
red
,
),
);
}
@override
void
initState
()
{
super
.
initState
();
controller
.
start
();
}
@override
...
...
@@ -57,20 +38,55 @@ class _BarcodeScannerReturningImageState
child:
Column
(
children:
[
Expanded
(
child:
barcode
?.
image
!=
null
?
Transform
.
rotate
(
angle:
90
*
pi
/
180
,
child:
Image
(
gaplessPlayback:
true
,
image:
MemoryImage
(
barcode
!.
image
!),
fit:
BoxFit
.
contain
,
),
)
:
const
Center
(
child:
StreamBuilder
<
BarcodeCapture
>(
stream:
controller
.
barcodes
,
builder:
(
context
,
snapshot
)
{
final
barcode
=
snapshot
.
data
;
if
(
barcode
==
null
)
{
return
const
Center
(
child:
Text
(
'Your scanned barcode will appear here!'
,
),
),
);
}
final
barcodeImage
=
barcode
.
image
;
if
(
barcodeImage
==
null
)
{
return
const
Center
(
child:
Text
(
'No image for this barcode.'
),
);
}
return
Image
.
memory
(
barcodeImage
,
fit:
BoxFit
.
contain
,
errorBuilder:
(
context
,
error
,
stackTrace
)
{
return
Center
(
child:
Text
(
'Could not decode image bytes.
$error
'
),
);
},
frameBuilder:
(
BuildContext
context
,
Widget
child
,
int
?
frame
,
bool
?
wasSynchronouslyLoaded
,
)
{
if
(
wasSynchronouslyLoaded
==
true
||
frame
!=
null
)
{
return
Transform
.
rotate
(
angle:
90
*
pi
/
180
,
child:
child
,
);
}
return
const
Center
(
child:
CircularProgressIndicator
(),
);
},
);
},
),
),
Expanded
(
flex:
2
,
...
...
@@ -84,11 +100,6 @@ class _BarcodeScannerReturningImageState
return
ScannerErrorWidget
(
error:
error
);
},
fit:
BoxFit
.
contain
,
onDetect:
(
barcode
)
{
setState
(()
{
this
.
barcode
=
barcode
;
});
},
),
Align
(
alignment:
Alignment
.
bottomCenter
,
...
...
@@ -99,69 +110,39 @@ class _BarcodeScannerReturningImageState
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
<
TorchState
>(
valueListenable:
controller
.
torchState
,
builder:
(
context
,
state
,
child
)
{
switch
(
state
)
{
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
(),
),
IconButton
(
color:
Colors
.
white
,
icon:
isStarted
?
const
Icon
(
Icons
.
stop
)
:
const
Icon
(
Icons
.
play_arrow
),
iconSize:
32.0
,
onPressed:
_startOrStop
,
ToggleFlashlightButton
(
controller:
controller
),
StartStopMobileScannerButton
(
controller:
controller
,
),
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
200
,
height:
50
,
child:
FittedBox
(
child:
Text
(
barcode
?.
barcodes
.
first
.
rawValue
??
Expanded
(
child:
Center
(
child:
StreamBuilder
<
BarcodeCapture
>(
stream:
controller
.
barcodes
,
builder:
(
context
,
snapshot
)
{
final
barcodes
=
snapshot
.
data
?.
barcodes
;
if
(
barcodes
==
null
||
barcodes
.
isEmpty
)
{
return
const
Text
(
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
!
.
copyWith
(
color:
Colors
.
white
),
),
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
20
,
),
);
}
return
Text
(
barcodes
.
first
.
rawValue
??
'No raw value'
,
overflow:
TextOverflow
.
fade
,
style:
const
TextStyle
(
color:
Colors
.
white
,
),
);
},
),
),
),
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
<
CameraFacing
>(
valueListenable:
controller
.
cameraFacingState
,
builder:
(
context
,
state
,
child
)
{
switch
(
state
)
{
case
CameraFacing
.
front
:
return
const
Icon
(
Icons
.
camera_front
);
case
CameraFacing
.
back
:
return
const
Icon
(
Icons
.
camera_rear
);
}
},
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
switchCamera
(),
),
SwitchCameraButton
(
controller:
controller
),
],
),
),
...
...
@@ -177,8 +158,8 @@ class _BarcodeScannerReturningImageState
}
@override
void
dispose
()
{
controller
.
dispose
();
Future
<
void
>
dispose
()
async
{
await
controller
.
dispose
();
super
.
dispose
();
}
}
...
...
Please
register
or
login
to post a comment