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
2024-09-10 13:46:22 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f332965954aff599262078821072ba09cef09404
f3329659
1 parent
3f5ad4de
add analyze image sample
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
76 deletions
example/lib/barcode_scanner_analyze_image.dart
example/lib/main.dart
example/lib/mobile_scanner_overlay.dart
example/lib/barcode_scanner_analyze_image.dart
0 → 100644
View file @
f332965
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:image_picker/image_picker.dart'
;
import
'package:mobile_scanner/mobile_scanner.dart'
;
class
BarcodeScannerAnalyzeImage
extends
StatefulWidget
{
const
BarcodeScannerAnalyzeImage
({
super
.
key
});
@override
State
<
BarcodeScannerAnalyzeImage
>
createState
()
=>
_BarcodeScannerAnalyzeImageState
();
}
class
_BarcodeScannerAnalyzeImageState
extends
State
<
BarcodeScannerAnalyzeImage
>
{
final
MobileScannerController
_controller
=
MobileScannerController
();
BarcodeCapture
?
_barcodeCapture
;
Future
<
void
>
_analyzeImageFromFile
()
async
{
try
{
final
XFile
?
file
=
await
ImagePicker
().
pickImage
(
source
:
ImageSource
.
gallery
);
if
(!
mounted
||
file
==
null
)
{
return
;
}
final
BarcodeCapture
?
barcodeCapture
=
await
_controller
.
analyzeImage
(
file
.
path
);
if
(
mounted
)
{
setState
(()
{
_barcodeCapture
=
barcodeCapture
;
});
}
}
catch
(
_
)
{}
}
@override
Widget
build
(
BuildContext
context
)
{
Widget
label
=
const
Text
(
'Pick a file to detect barcode'
);
if
(
_barcodeCapture
!=
null
)
{
label
=
Text
(
_barcodeCapture
?.
barcodes
.
firstOrNull
?.
displayValue
??
'No barcode detected'
,
);
}
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Analyze image from file'
)),
body:
Column
(
children:
[
Expanded
(
child:
Center
(
child:
ElevatedButton
(
onPressed:
kIsWeb
?
null
:
_analyzeImageFromFile
,
child:
kIsWeb
?
const
Text
(
'Analyze image is not supported on web'
)
:
const
Text
(
'Choose file'
),
),
),
),
Expanded
(
child:
Center
(
child:
label
)),
],
),
);
}
@override
void
dispose
()
{
_controller
.
dispose
();
super
.
dispose
();
}
}
...
...
example/lib/main.dart
View file @
f332965
import
'package:flutter/material.dart'
;
import
'package:mobile_scanner_example/barcode_scanner_analyze_image.dart'
;
import
'package:mobile_scanner_example/barcode_scanner_controller.dart'
;
import
'package:mobile_scanner_example/barcode_scanner_listview.dart'
;
import
'package:mobile_scanner_example/barcode_scanner_pageview.dart'
;
...
...
@@ -20,95 +21,75 @@ void main() {
class
MyHome
extends
StatelessWidget
{
const
MyHome
({
super
.
key
});
Widget
_buildItem
(
BuildContext
context
,
String
label
,
Widget
page
)
{
return
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Center
(
child:
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
page
,
),
);
},
child:
Text
(
label
),
),
),
);
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Mobile Scanner Example'
)),
body:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceAround
,
child:
ListView
(
children:
[
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerSimple
(),
),
);
},
child:
const
Text
(
'MobileScanner Simple'
),
_buildItem
(
context
,
'MobileScanner Simple'
,
const
BarcodeScannerSimple
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerListView
(),
),
);
},
child:
const
Text
(
'MobileScanner with ListView'
),
_buildItem
(
context
,
'MobileScanner with ListView'
,
const
BarcodeScannerListView
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerWithController
(),
),
);
},
child:
const
Text
(
'MobileScanner with Controller'
),
_buildItem
(
context
,
'MobileScanner with Controller'
,
const
BarcodeScannerWithController
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerWithScanWindow
(),
),
);
},
child:
const
Text
(
'MobileScanner with ScanWindow'
),
_buildItem
(
context
,
'MobileScanner with ScanWindow'
,
const
BarcodeScannerWithScanWindow
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerReturningImage
(),
),
);
},
child:
const
Text
(
'MobileScanner with Controller (returning image)'
,
),
_buildItem
(
context
,
'MobileScanner with Controller (return image)'
,
const
BarcodeScannerReturningImage
(),
),
_buildItem
(
context
,
'MobileScanner with zoom slider'
,
const
BarcodeScannerWithZoom
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerWithZoom
(),
),
);
},
child:
const
Text
(
'MobileScanner with zoom slider'
),
_buildItem
(
context
,
'MobileScanner with PageView'
,
const
BarcodeScannerPageView
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
const
BarcodeScannerPageView
(),
),
);
},
child:
const
Text
(
'MobileScanner pageView'
),
_buildItem
(
context
,
'MobileScanner with Overlay'
,
const
BarcodeScannerWithOverlay
(),
),
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
push
(
MaterialPageRoute
(
builder:
(
context
)
=>
BarcodeScannerWithOverlay
(),
),
);
},
child:
const
Text
(
'MobileScanner with Overlay'
),
_buildItem
(
context
,
'Analyze image from file'
,
const
BarcodeScannerAnalyzeImage
(),
),
],
),
...
...
example/lib/mobile_scanner_overlay.dart
View file @
f332965
...
...
@@ -5,6 +5,8 @@ import 'package:mobile_scanner_example/scanner_button_widgets.dart';
import
'package:mobile_scanner_example/scanner_error_widget.dart'
;
class
BarcodeScannerWithOverlay
extends
StatefulWidget
{
const
BarcodeScannerWithOverlay
({
super
.
key
});
@override
_BarcodeScannerWithOverlayState
createState
()
=>
_BarcodeScannerWithOverlayState
();
...
...
Please
register
or
login
to post a comment