mvbarcodescan 0.0.2 mvbarcodescan: ^0.0.2 copied to clipboard
A new Flutter plugin to scan barcode and qrcodes using Google Mobile vision & Apple AVFoundation
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:mvbarcodescan/mvbarcodescan.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _scannedBarCode = 'Unknown';
@override
void initState() {
super.initState();
// initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await Mvbarcodescan.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> scanBarCode() async {
String barCode;
try {
barCode = await Mvbarcodescan.scan;
} on PlatformException {
barCode = '';
}
setState(() {
_scannedBarCode = barCode;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
scanBarCode();
},
child: Icon(Icons.camera),
),
appBar: AppBar(
title: const Text('Barcode Scan Example'),
),
body: Center(
child: Text('Scanned Barcode : $_scannedBarCode\n'),
),
),
);
}
}