The QR Code Scanner package for Appeto SDK.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

90 行
2.2 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. }