qr code scanner
a qr code scanner that works on both ios and android by natively embedding the platform view within flutter. the integration with flutter is seamless, much better than jumping into a native activity or a viewcontroller to perform the scan.
screenshots for qr code scanner
android | |
---|---|
ios | |
get scanned qr code
when a qr code is recognized, the text identified will be set in ‘qrtext’.
class _qrviewexamplestate extends state<qrviewexample> {
final globalkey qrkey = globalkey(debuglabel: 'qr');
var qrtext = "";
qrviewcontroller controller;
@override
widget build(buildcontext context) {
return scaffold(
body: column(
children: <widget>[
expanded(
flex: 5,
child: qrview(
key: qrkey,
onqrviewcreated: _onqrviewcreated,
),
),
expanded(
flex: 1,
child: center(
child: text('scan result: $qrtext'),
),
)
],
),
);
}
void _onqrviewcreated(qrviewcontroller controller) {
this.controller = controller;
controller.scanneddatastream.listen((scandata) {
setstate(() {
qrtext = scandata;
});
});
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
}
ios integration
in order to use this plugin, add the following to your info.plist file:
<key>io.flutter.embedded_views_preview</key>
<true/>
flip camera (back/front)
the default camera is the back camera.
controller.flipcamera();
flash (off/on)
by default, flash is off.
controller.toggleflash();
resume/pause
pause camera stream and scanner.
controller.pause();
resume camera stream and scanner.
controller.resume();
todo’s:
- ios native embedding is written to match what is supported in the framework as of the date of publication of this package. it needs to be improved as the framework support improves.
- in future, options will be provided for default states.
- finally, i welcome pr’s to make it better :), thanks
Comments are closed.