flutter_plugin_qr_scanner.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'dart:async';
  2. import 'dart:ui';
  3. import 'package:flutter/services.dart';
  4. class QrScanner {
  5. static const MethodChannel _channel = const MethodChannel('scanner');
  6. static Future<String> scan({
  7. String title = "",
  8. Color laserColor,
  9. bool playBeep = false, //android support
  10. String promptMessage,
  11. String errorMsg, //android support
  12. String permissionDeniedText,
  13. String messageConfirmText,
  14. String messageCancelText,
  15. }) async {
  16. Map<String, dynamic> arguments = {
  17. Intents.TITLE: title,
  18. Intents.KEY_PLAY_BEEP: playBeep,
  19. };
  20. if (laserColor != null)
  21. arguments[Intents.LASER_COLOR] = '#${laserColor.value.toRadixString(16)}';
  22. if (promptMessage != null)
  23. arguments[Intents.PROMPT_MESSAGE] = promptMessage;
  24. if (errorMsg != null)
  25. arguments[Intents.ERROR_MESSAGE] = errorMsg;
  26. if (permissionDeniedText != null)
  27. arguments[Intents.PERMISSION_DENIED_MESSAGE] = permissionDeniedText;
  28. if (messageConfirmText != null)
  29. arguments[Intents.MESSAGE_CONFIRM_TEXT] = messageConfirmText;
  30. if (messageCancelText != null)
  31. arguments[Intents.MESSAGE_CANCEL_TEXT] = messageCancelText;
  32. final String code = await _channel.invokeMethod('scan', arguments);
  33. return code;
  34. }
  35. }
  36. class Intents {
  37. static const TITLE = "SCAN_TITLE";
  38. static const LASER_COLOR = "LASER_COLOR";
  39. static const KEY_PLAY_BEEP = "KEY_PLAY_BEEP";
  40. static const PROMPT_MESSAGE = "PROMPT_MESSAGE";
  41. static const ERROR_MESSAGE = "ERROR_MESSAGE";
  42. static const PERMISSION_DENIED_MESSAGE = "PERMISSION_DENIED_MESSAGE";
  43. static const MESSAGE_CONFIRM_TEXT = "MESSAGE_CONFIRM_TEXT";
  44. static const MESSAGE_CANCEL_TEXT = "MESSAGE_CANCEL_TEXT";
  45. }