qrcode_flutter 2.0.1 qrcode_flutter: ^2.0.1 copied to clipboard
Flutter plugin for scanning QR codes.You can customize your page by using PlatformView.Scanning Picture from path (photo album).
qrcode_flutter #
RoadMap #
- ❌ add annotation
- ❌ support Flutter Web
introduce #
Flutter plugin for scanning QR codes.You can customize your page by using PlatformView.Scanning Picture from path(photo album).
You can download flutter_demo.apk for testing
Usage #
class _MyAppState extends State<MyApp> {
QRCaptureController _controller = QRCaptureController();
bool _isTorchOn = false;
@override
void initState() {
super.initState();
_controller.onCapture((data) {
print('$data');
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('scan'),
actions: <Widget>[
FlatButton(
onPressed: () async {
PickedFile image =
await ImagePicker().getImage(source: ImageSource.gallery);
var qrCodeResult =
await QRCaptureController.getQrCodeByImagePath(image.path);
setState(() {
_captureText = qrCodeResult.join('\n');
});
},
child: Text('photoAlbum', style: TextStyle(color: Colors.white)),
),
],
),
body: Stack(
alignment: Alignment.center,
children: <Widget>[
QRCaptureView(controller: _controller),
Align(
alignment: Alignment.bottomCenter,
child: _buildToolBar(),
)
],
),
),
);
}
Widget _buildToolBar() {
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
_controller.pause();
},
child: Text('pause'),
),
FlatButton(
onPressed: () {
if (_isTorchOn) {
_controller.torchMode = CaptureTorchMode.off;
} else {
_controller.torchMode = CaptureTorchMode.on;
}
_isTorchOn = !_isTorchOn;
},
child: Text('torch'),
),
FlatButton(
onPressed: () {
_controller.resume();
},
child: Text('resume'),
)
],
);
}
}
Integration #
iOS #
To use on iOS, you must add the following to your Info.plist
<key>NSCameraUsageDescription</key>
<string>Camera permission is required for qrcode scanning.</string>
<key>io.flutter.embedded_views_preview</key>
<true/>