The QR Code Scanner package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

95 lignes
2.3 KiB

  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. typedef void QRViewCreatedCallback(QRViewController controller);
  5. class QRView extends StatefulWidget {
  6. const QRView({
  7. Key key,
  8. this.onQRViewCreated,
  9. }) : super(key: key);
  10. final QRViewCreatedCallback onQRViewCreated;
  11. @override
  12. State<StatefulWidget> createState() => _QRViewState();
  13. }
  14. class _QRViewState extends State<QRView> {
  15. @override
  16. Widget build(BuildContext context) {
  17. var androidView = AndroidView(
  18. viewType: 'net.touchcapture.qr.flutterqr/qrview',
  19. onPlatformViewCreated: _onPlatformViewCreated,
  20. );
  21. if (defaultTargetPlatform == TargetPlatform.android) {
  22. return androidView;
  23. }
  24. if (defaultTargetPlatform == TargetPlatform.iOS) {
  25. return UiKitView(
  26. viewType: 'net.touchcapture.qr.flutterqr/qrview',
  27. onPlatformViewCreated: _onPlatformViewCreated,
  28. creationParams: _CreationParams.fromWidget(0, 0).toMap(),
  29. creationParamsCodec: StandardMessageCodec(),
  30. );
  31. }
  32. return Text(
  33. '$defaultTargetPlatform is not yet supported by the text_view plugin');
  34. }
  35. void _onPlatformViewCreated(int id) {
  36. if (widget.onQRViewCreated == null) {
  37. return;
  38. }
  39. widget.onQRViewCreated(new QRViewController._(id));
  40. }
  41. }
  42. class _CreationParams {
  43. _CreationParams({this.width, this.height});
  44. static _CreationParams fromWidget(double width, double height) {
  45. return _CreationParams(
  46. width: width,
  47. height: height,
  48. );
  49. }
  50. final double width;
  51. final double height;
  52. Map<String, dynamic> toMap() {
  53. return <String, dynamic>{
  54. 'width': width,
  55. 'height': height,
  56. };
  57. }
  58. }
  59. class QRViewController {
  60. QRViewController._(int id)
  61. : channel = MethodChannel('net.touchcapture.qr.flutterqr/qrview_$id');
  62. final MethodChannel channel;
  63. void init(GlobalKey qrKey) {
  64. if (defaultTargetPlatform == TargetPlatform.iOS) {
  65. final RenderBox renderBox = qrKey.currentContext.findRenderObject();
  66. channel.invokeMethod("setDimensions",
  67. {"width": renderBox.size.width, "height": renderBox.size.height});
  68. }
  69. }
  70. void flipCamera(){
  71. channel.invokeMethod("flipCamera");
  72. }
  73. void flipFlash(){
  74. channel.invokeMethod("flipFlash");
  75. }
  76. }