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 11:44:10 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1d68f6b2051b8f19cd1352d2d5fb2349de5e660b
1d68f6b2
1 parent
726de01d
fix the pageview sample
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
60 deletions
example/lib/barcode_scanner_pageview.dart
example/lib/barcode_scanner_pageview.dart
View file @
1d68f6b
import
'dart:async'
;
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
...
...
@@ -9,62 +11,15 @@ class BarcodeScannerPageView extends StatefulWidget {
State
<
BarcodeScannerPageView
>
createState
()
=>
_BarcodeScannerPageViewState
();
}
class
_BarcodeScannerPageViewState
extends
State
<
BarcodeScannerPageView
>
with
SingleTickerProviderStateMixin
{
BarcodeCapture
?
capture
;
Widget
cameraView
()
{
return
Builder
(
builder:
(
context
)
{
return
Stack
(
children:
[
MobileScanner
(
startDelay:
true
,
controller:
MobileScannerController
(
torchEnabled:
true
),
fit:
BoxFit
.
contain
,
errorBuilder:
(
context
,
error
,
child
)
{
return
ScannerErrorWidget
(
error:
error
);
},
onDetect:
(
capture
)
{
setState
(()
{
this
.
capture
=
capture
;
});
},
),
Align
(
alignment:
Alignment
.
bottomCenter
,
child:
Container
(
alignment:
Alignment
.
bottomCenter
,
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
Center
(
child:
SizedBox
(
width:
MediaQuery
.
of
(
context
).
size
.
width
-
120
,
height:
50
,
child:
FittedBox
(
child:
Text
(
capture
?.
barcodes
.
first
.
rawValue
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
!
.
copyWith
(
color:
Colors
.
white
),
),
),
),
),
],
),
),
),
],
);
},
);
class
_BarcodeScannerPageViewState
extends
State
<
BarcodeScannerPageView
>
{
final
MobileScannerController
scannerController
=
MobileScannerController
();
final
PageController
pageController
=
PageController
();
@override
void
initState
()
{
super
.
initState
();
scannerController
.
start
();
}
@override
...
...
@@ -73,13 +28,86 @@ class _BarcodeScannerPageViewState extends State<BarcodeScannerPageView>
appBar:
AppBar
(
title:
const
Text
(
'With PageView'
)),
backgroundColor:
Colors
.
black
,
body:
PageView
(
controller:
pageController
,
onPageChanged:
(
index
)
async
{
// Stop the camera view for the current page,
// and then restart the camera for the new page.
await
scannerController
.
stop
();
// When switching pages, add a delay to the next start call.
// Otherwise the camera will start before the next page is displayed.
await
Future
.
delayed
(
const
Duration
(
seconds:
1
,
milliseconds:
500
));
if
(!
mounted
)
{
return
;
}
scannerController
.
start
();
},
children:
[
cameraView
(),
Container
(),
cameraView
(),
cameraView
(),
_BarcodeScannerPage
(
controller:
scannerController
),
const
SizedBox
(),
_BarcodeScannerPage
(
controller:
scannerController
),
_BarcodeScannerPage
(
controller:
scannerController
),
],
),
);
}
@override
Future
<
void
>
dispose
()
async
{
await
scannerController
.
dispose
();
pageController
.
dispose
();
super
.
dispose
();
}
}
class
_BarcodeScannerPage
extends
StatelessWidget
{
const
_BarcodeScannerPage
({
required
this
.
controller
});
final
MobileScannerController
controller
;
@override
Widget
build
(
BuildContext
context
)
{
return
Stack
(
children:
[
MobileScanner
(
controller:
controller
,
fit:
BoxFit
.
contain
,
errorBuilder:
(
context
,
error
,
child
)
{
return
ScannerErrorWidget
(
error:
error
);
},
),
Align
(
alignment:
Alignment
.
bottomCenter
,
child:
Container
(
alignment:
Alignment
.
bottomCenter
,
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
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!'
,
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
20
),
);
}
return
Text
(
barcodes
.
first
.
rawValue
??
'No raw value'
,
overflow:
TextOverflow
.
fade
,
style:
const
TextStyle
(
color:
Colors
.
white
),
);
},
),
),
),
),
],
);
}
}
...
...
Please
register
or
login
to post a comment