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-16 16:06:27 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
da838a75b95507c7a481d8b2f53ba2ab9c84e450
da838a75
1 parent
14972d97
remove stream subscriptions & MediaQueryData.size usages
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
127 deletions
example/lib/barcode_scanner_controller.dart
example/lib/barcode_scanner_pageview.dart
example/lib/barcode_scanner_returning_image.dart
example/lib/barcode_scanner_window.dart
example/lib/barcode_scanner_zoom.dart
example/lib/barcode_scanner_controller.dart
View file @
da838a7
...
...
@@ -2,6 +2,7 @@ import 'dart:async';
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanned_barcode_label.dart'
;
import
'package:mobile_scanner_example/scanner_button_widgets.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
...
...
@@ -15,8 +16,6 @@ class BarcodeScannerWithController extends StatefulWidget {
class
_BarcodeScannerWithControllerState
extends
State
<
BarcodeScannerWithController
>
{
BarcodeCapture
?
barcode
;
final
MobileScannerController
controller
=
MobileScannerController
(
torchEnabled:
true
,
useNewCameraSelector:
true
,
// formats: [BarcodeFormat.qrCode]
...
...
@@ -26,21 +25,9 @@ class _BarcodeScannerWithControllerState
// returnImage: false,
);
StreamSubscription
<
Object
?>?
_barcodesSubscription
;
@override
void
initState
()
{
super
.
initState
();
_barcodesSubscription
=
controller
.
barcodes
.
listen
((
event
)
{
if
(!
context
.
mounted
)
{
return
;
}
setState
(()
{
barcode
=
event
;
});
});
controller
.
start
();
}
...
...
@@ -69,20 +56,9 @@ class _BarcodeScannerWithControllerState
children:
[
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
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
!
.
copyWith
(
color:
Colors
.
white
),
),
),
Expanded
(
child:
Center
(
child:
ScannedBarcodeLabel
(
barcodes:
controller
.
barcodes
),
),
),
SwitchCameraButton
(
controller:
controller
),
...
...
@@ -98,7 +74,6 @@ class _BarcodeScannerWithControllerState
@override
Future
<
void
>
dispose
()
async
{
_barcodesSubscription
?.
cancel
();
await
controller
.
dispose
();
super
.
dispose
();
}
...
...
example/lib/barcode_scanner_pageview.dart
View file @
da838a7
...
...
@@ -2,6 +2,7 @@ import 'dart:async';
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanned_barcode_label.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
class
BarcodeScannerPageView
extends
StatefulWidget
{
...
...
@@ -85,25 +86,7 @@ class _BarcodeScannerPage extends StatelessWidget {
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
),
);
},
),
child:
ScannedBarcodeLabel
(
barcodes:
controller
.
barcodes
),
),
),
),
...
...
example/lib/barcode_scanner_returning_image.dart
View file @
da838a7
...
...
@@ -2,6 +2,7 @@ import 'dart:math';
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanned_barcode_label.dart'
;
import
'package:mobile_scanner_example/scanner_button_widgets.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
...
...
@@ -116,29 +117,8 @@ class _BarcodeScannerReturningImageState
),
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!'
,
style:
TextStyle
(
color:
Colors
.
white
,
fontSize:
20
,
),
);
}
return
Text
(
barcodes
.
first
.
rawValue
??
'No raw value'
,
overflow:
TextOverflow
.
fade
,
style:
const
TextStyle
(
color:
Colors
.
white
,
),
);
},
child:
ScannedBarcodeLabel
(
barcodes:
controller
.
barcodes
,
),
),
),
...
...
example/lib/barcode_scanner_window.dart
View file @
da838a7
...
...
@@ -3,6 +3,7 @@ import 'dart:io';
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanned_barcode_label.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
...
...
@@ -117,33 +118,7 @@ class _BarcodeScannerWithScanWindowState
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
16
,
vertical:
8
),
height:
100
,
color:
Colors
.
black
.
withOpacity
(
0.4
),
child:
StreamBuilder
<
BarcodeCapture
>(
stream:
controller
.
barcodes
,
builder:
(
context
,
snapshot
)
{
final
barcodeCapture
=
snapshot
.
data
;
String
displayValue
=
'Scan something!'
;
if
(
barcodeCapture
!=
null
&&
barcodeCapture
.
barcodes
.
isNotEmpty
)
{
final
String
?
value
=
barcodeCapture
.
barcodes
.
first
.
displayValue
;
if
(
value
!=
null
)
{
displayValue
=
value
;
}
}
return
Text
(
displayValue
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
!
.
copyWith
(
color:
Colors
.
white
),
);
},
),
child:
ScannedBarcodeLabel
(
barcodes:
controller
.
barcodes
),
),
),
],
...
...
example/lib/barcode_scanner_zoom.dart
View file @
da838a7
...
...
@@ -2,6 +2,7 @@ import 'dart:async';
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
import
'package:mobile_scanner_example/scanned_barcode_label.dart'
;
import
'package:mobile_scanner_example/scanner_button_widgets.dart'
;
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
...
...
@@ -14,29 +15,15 @@ class BarcodeScannerWithZoom extends StatefulWidget {
}
class
_BarcodeScannerWithZoomState
extends
State
<
BarcodeScannerWithZoom
>
{
BarcodeCapture
?
barcode
;
final
MobileScannerController
controller
=
MobileScannerController
(
torchEnabled:
true
,
);
double
_zoomFactor
=
0.0
;
StreamSubscription
<
Object
?>?
_barcodesSubscription
;
@override
void
initState
()
{
super
.
initState
();
_barcodesSubscription
=
controller
.
barcodes
.
listen
((
event
)
{
if
(!
context
.
mounted
)
{
return
;
}
setState
(()
{
barcode
=
event
;
});
});
controller
.
start
();
}
...
...
@@ -113,20 +100,10 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> {
children:
[
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
??
'Scan something!'
,
overflow:
TextOverflow
.
fade
,
style:
Theme
.
of
(
context
)
.
textTheme
.
headlineMedium
!
.
copyWith
(
color:
Colors
.
white
),
),
Expanded
(
child:
Center
(
child:
ScannedBarcodeLabel
(
barcodes:
controller
.
barcodes
,
),
),
),
...
...
@@ -145,7 +122,6 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> {
@override
Future
<
void
>
dispose
()
async
{
_barcodesSubscription
?.
cancel
();
await
controller
.
dispose
();
super
.
dispose
();
}
...
...
Please
register
or
login
to post a comment