flutter fast qr reader
fast qr reader widget is a flutter plugin for ios and android allowing access to the device cameras to scan multiple types of codes (qr, pdf417, code39, etc). heavily based on the camera.
features:
- display live camera preview in a widget.
- uses native avfoundation code detection in ios
- uses ml kit in android
installation
first, add fast_qr_reader_view
as a dependency in your pubspec.yaml file.
ios
add a row to the ios/runner/info.plist
with the key privacy - camera usage description
and a usage description.
or in text format add the key:
<key>nscamerausagedescription</key>
<string>can i use the camera please?</string>
android
add firebase to your project following this step (only that step, not the entire guide).
change the minimum android sdk version to 21 (or higher) in your android/app/build.gradle
file.
minsdkversion 21
example
here is a small example flutter app displaying a full screen camera preview.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fast_qr_reader_view/fast_qr_reader_view.dart';
list<cameradescription> cameras;
future<null> main() async {
cameras = await availablecameras();
runapp(new cameraapp());
}
class cameraapp extends statefulwidget {
@override
_cameraappstate createstate() => new _cameraappstate();
}
class _cameraappstate extends state<cameraapp> {
qrreadercontroller controller;
@override
void initstate() {
super.initstate();
controller = new qrreadercontroller(cameras[0], resolutionpreset.medium, [codeformat.qr], (dynamic value){
print(value); // the result!
// ... do something
// wait 3 seconds then start scanning again.
new future.delayed(const duration(seconds: 3), controller.startscanning);
});
controller.initialize().then((_) {
if (!mounted) {
return;
}
setstate(() {});
controller.startscanning();
});
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
@override
widget build(buildcontext context) {
if (!controller.value.isinitialized) {
return new container();
}
return new aspectratio(
aspectratio:
controller.value.aspectratio,
child: new qrreaderpreview(controller));
}
}
for a more elaborate usage example see here.
Comments are closed.