majascan 0.3.7 majascan: ^0.3.7 copied to clipboard
A qr code scanner flutter plugin project. Using method channel open native camera page scan QR code. Support iOS, Android.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:majascan/majascan.dart';
void main() => runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
));
class HomePage extends StatefulWidget {
@override
HomePageState createState() {
return new HomePageState();
}
}
class HomePageState extends State<HomePage> {
String result = "Hey there !";
Future _scanQR() async {
try {
String qrResult = await MajaScan.startScan(
title: "QRcode scanner",
titleColor: Colors.amberAccent[700],
qRCornerColor: Colors.orange,
qRScannerColor: Colors.orange);
setState(() {
result = qrResult;
});
} on PlatformException catch (ex) {
if (ex.code == MajaScan.CameraAccessDenied) {
setState(() {
result = "Camera permission was denied";
});
} else {
setState(() {
result = "Unknown Error $ex";
});
}
} on FormatException {
setState(() {
result = "You pressed the back button before scanning anything";
});
} catch (ex) {
setState(() {
result = "Unknown Error $ex";
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.amberAccent,
title: Text("QR Scanner"),
),
body: Center(
child: Text(
result,
style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),
),
),
floatingActionButton: FloatingActionButton.extended(
icon: Icon(Icons.camera_alt),
label: Text("Scan"),
onPressed: _scanQR,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}