qrcode_plugin 0.0.1 qrcode_plugin: ^0.0.1 copied to clipboard
A new Flutter plugin for Qrcode.
qrcode_plugin #
A new Flutter plugin for Qrcode. Supports iOS and Android
Getting Started #
This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
Usage #
To use this plugin, and qrcode_plugin as dependency in your pubspec.yaml file
Example #
class CameraPageState extends State<CameraPage> with WidgetsBindingObserver {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
CameraController cameraController;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
availableCameras().then((cameras) {
initCamera(cameras[0]);
});
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (cameraController == null || !cameraController.value.isInitialized) {
return;
}
if (state == AppLifecycleState.inactive) {
cameraController.dispose();
} else if (state == AppLifecycleState.resumed) {
initCamera(cameraController.description);
}
}
@override
void dispose() {
super.dispose();
cameraController.dispose();
WidgetsBinding.instance.removeObserver(this);
}
void initCamera(CameraDescription description) {
cameraController?.dispose();
cameraController = CameraController(description, ResolutionPreset.high,
onScanSuccess: (content) {
showInSnackBar(content);
});
cameraController.addListener(() {
if (mounted) {
setState(() {
if (cameraController.value.hasError) {
showInSnackBar(
'Camera error ${cameraController.value.errorDescription}');
}
});
}
});
cameraController.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: const Text("Camera Demo"),
),
body: Center(child: _buildBody(context)),
);
}
Widget _buildBody(BuildContext context) {
if (cameraController == null || !cameraController.value.isInitialized) {
return CircularProgressIndicator();
}
return Stack(
children: <Widget>[
AspectRatio(
aspectRatio: cameraController.value.aspectRatio,
child: CameraPreview(cameraController),
),
Align(
alignment: Alignment.bottomCenter,
child: Row(
children: <Widget>[
RaisedButton(
onPressed: () {
cameraController.startPreview();
},
child: Text("start preview"),
),
RaisedButton(
onPressed: () {
cameraController.stopPreview();
},
child: Text("stop preview"),
),
],
),
),
],
);
}
void showInSnackBar(String message) {
_scaffoldKey.currentState.showSnackBar(SnackBar(content: Text(message)));
}
}