-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathbarcode.dart
95 lines (85 loc) · 2.45 KB
/
barcode.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'dart:async';
import 'dart:io';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String barcode = "";
@override
initState() {
super.initState();
}
File galleryFile;
imageSelectorGallery() async {
galleryFile = await ImagePicker.pickImage(
source: ImageSource.gallery,
// maxHeight: 50.0,
// maxWidth: 50.0,
);
print("You selected gallery image : " + galleryFile.path);
setState(() {});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Scan Barcode'),
),
body: new Center(
child: new Column(
children: <Widget>[
new Container(
child: new RaisedButton(
onPressed: barcodeScanning, child: new Text("Capture image")),
padding: const EdgeInsets.all(8.0),
),
new Padding(
padding: const EdgeInsets.all(8.0),
),
new Text("Barcode Number after Scan : " + barcode),
// displayImage(),
],
),
)),
);
}
Widget displayImage() {
return new SizedBox(
height: 300.0,
width: 400.0,
child: galleryFile == null
? new Text('Sorry nothing to display')
: new Image.file(galleryFile),
);
}
// Method for scanning barcode....
Future barcodeScanning() async {
//imageSelectorGallery();
try {
String barcode = await BarcodeScanner.scan();
setState(() => this.barcode = barcode);
} on PlatformException catch (e) {
if (e.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
this.barcode = 'No camera permission!';
});
} else {
setState(() => this.barcode = 'Unknown error: $e');
}
} on FormatException {
setState(() => this.barcode =
'Nothing captured.');
} catch (e) {
setState(() => this.barcode = 'Unknown error: $e');
}
}
}