qrscan 0.2.8 qrscan: ^0.2.8 copied to clipboard
A Plug-in for dart, which help you scanning barcode and qrcode with android device.
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:qrscan/qrscan.dart' as scanner;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String barcode = '';
Uint8List bytes = Uint8List(200);
@override
initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Qrcode Scanner Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 200,
height: 200,
child: Image.memory(bytes),
),
Text('RESULT $barcode'),
RaisedButton(onPressed: _scan, child: Text("Scan")),
RaisedButton(onPressed: _scanPhoto, child: Text("Scan Photo")),
RaisedButton(onPressed: _generateBarCode, child: Text("Generate Barcode")),
],
),
),
),
);
}
Future _scan() async {
String barcode = await scanner.scan();
setState(() => this.barcode = barcode);
}
Future _scanPhoto() async {
String barcode = await scanner.scanPhoto();
setState(() => this.barcode = barcode);
}
Future _generateBarCode() async {
Uint8List result = await scanner.generateBarCode('https://github.com/leyan95/qrcode_scanner');
this.setState(() => this.bytes = result);
}
}