2017-10-30 01:05:11 +08:00
|
|
|
import 'dart:async';
|
|
|
|
|
2017-10-30 07:35:38 +08:00
|
|
|
import 'package:barcode_scan/barcode_scanner.dart';
|
2017-10-30 01:05:11 +08:00
|
|
|
import 'package:flutter/material.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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return new MaterialApp(
|
|
|
|
home: new Scaffold(
|
|
|
|
appBar: new AppBar(
|
|
|
|
title: new Text('Barcode Scanner Example'),
|
|
|
|
),
|
|
|
|
body: new Center(
|
|
|
|
child: new Column(
|
|
|
|
children: <Widget>[
|
|
|
|
new Container(
|
|
|
|
child: new MaterialButton(
|
|
|
|
onPressed: scan, child: new Text("Scan")),
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
),
|
|
|
|
new Text(barcode),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future scan() async {
|
2017-10-30 07:35:38 +08:00
|
|
|
String barcode = await BarcodeScanner.scan();
|
2017-10-30 01:05:11 +08:00
|
|
|
setState(() => this.barcode = barcode);
|
|
|
|
}
|
|
|
|
}
|