Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AseemWangoo authored Jul 6, 2018
1 parent 13e457a commit 94b679b
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions barcode.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,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');
}
}
}

0 comments on commit 94b679b

Please sign in to comment.