Skip to content
Permalink
Branch: master
Find file Copy path
1 contributor

Users who have contributed to this file

96 lines (85 sloc) 2.45 KB
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');
}
}
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.