majascan 0.1.3 majascan: ^0.1.3 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: "QQRcode scanner",
titleColor: Color.fromARGB(255, 255, 136, 0),//Colors.amberAccent[300]
);
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,
);
}
}