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.
 
 
 
 
 
 

71 lignes
1.8 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:qr_code_scanner/qr_code_scanner.dart';
  4. void main() => runApp(MaterialApp(home: QRViewExample()));
  5. class QRViewExample extends StatefulWidget {
  6. const QRViewExample({
  7. Key key,
  8. }) : super(key: key);
  9. @override
  10. State<StatefulWidget> createState() => _QRViewExampleState();
  11. }
  12. class _QRViewExampleState extends State<QRViewExample> {
  13. final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
  14. var qrText = "";
  15. QRViewController controller;
  16. @override
  17. Widget build(BuildContext context) {
  18. return Scaffold(
  19. body: Column(
  20. children: <Widget>[
  21. Expanded(
  22. child: QRView(
  23. key: qrKey,
  24. onQRViewCreated: _onQRViewCreated,
  25. ),
  26. flex: 4,
  27. ),
  28. Expanded(
  29. child: Column(children:
  30. <Widget>[
  31. Text("This is the result of scan: $qrText"),
  32. RaisedButton(
  33. onPressed: (){
  34. if(controller != null){
  35. controller.flipCamera();
  36. }
  37. },
  38. child: Text(
  39. 'Flip',
  40. style: TextStyle(fontSize: 20)
  41. ),
  42. )
  43. ],
  44. ),
  45. flex: 1,
  46. )
  47. ],
  48. ),
  49. );
  50. }
  51. void _onQRViewCreated(QRViewController controller) {
  52. final channel = controller.channel;
  53. controller.init(qrKey);
  54. this.controller = controller;
  55. channel.setMethodCallHandler((MethodCall call) async {
  56. switch (call.method) {
  57. case "onRecognizeQR":
  58. dynamic arguments = call.arguments;
  59. setState(() {
  60. qrText = arguments.toString();
  61. });
  62. }
  63. });
  64. }
  65. }