qrtypes.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import 'dart:ui';
  2. /// Represents a specific element / part of a QR code. This is used to isolate
  3. /// the different parts so that we can style and modify specific parts
  4. /// independently.
  5. enum QrCodeElement {
  6. /// The 'stroke' / outer square of the QR code finder pattern element.
  7. finderPatternOuter,
  8. /// The inner/in-between square of the QR code finder pattern element.
  9. finderPatternInner,
  10. /// The "dot" square of the QR code finder pattern element.
  11. finderPatternDot,
  12. /// The individual pixels of the QR code
  13. codePixel,
  14. /// The "empty" pixels of the QR code
  15. codePixelEmpty,
  16. }
  17. /// Enumeration representing the three finder pattern (square 'eye') locations.
  18. enum FinderPatternPosition {
  19. /// The top left position.
  20. topLeft,
  21. /// The top right position.
  22. topRight,
  23. /// The bottom left position.
  24. bottomLeft,
  25. }
  26. /// Enumeration representing the finder pattern eye's shape.
  27. enum QrEyeShape {
  28. /// Use square eye frame.
  29. square,
  30. /// Use circular eye frame.
  31. circle,
  32. }
  33. /// Enumeration representing the shape of Data modules inside QR.
  34. enum QrDataModuleShape {
  35. /// Use square dots.
  36. square,
  37. /// Use circular dots.
  38. circle,
  39. }
  40. /// Styling options for finder pattern eye.
  41. class QrEyeStyle {
  42. /// Create a new set of styling options for QR Eye.
  43. const QrEyeStyle({this.eyeShape, this.color});
  44. /// Eye shape.
  45. final QrEyeShape? eyeShape;
  46. /// Color to tint the eye.
  47. final Color? color;
  48. @override
  49. int get hashCode => eyeShape.hashCode ^ color.hashCode;
  50. @override
  51. bool operator ==(Object other) {
  52. if (other is QrEyeStyle) {
  53. return eyeShape == other.eyeShape && color == other.color;
  54. }
  55. return false;
  56. }
  57. }
  58. /// Styling options for data module.
  59. class QrDataModuleStyle {
  60. /// Create a new set of styling options for data modules.
  61. const QrDataModuleStyle({
  62. this.dataModuleShape,
  63. this.color,
  64. });
  65. /// Eye shape.
  66. final QrDataModuleShape? dataModuleShape;
  67. /// Color to tint the data modules.
  68. final Color? color;
  69. @override
  70. int get hashCode => dataModuleShape.hashCode ^ color.hashCode;
  71. @override
  72. bool operator ==(Object other) {
  73. if (other is QrDataModuleStyle) {
  74. return dataModuleShape == other.dataModuleShape && color == other.color;
  75. }
  76. return false;
  77. }
  78. }
  79. /// Styling options for any embedded image overlay
  80. class QrEmbeddedImageStyle {
  81. /// Create a new set of styling options.
  82. QrEmbeddedImageStyle({
  83. this.size,
  84. this.color,
  85. });
  86. /// The size of the image. If one dimension is zero then the other dimension
  87. /// will be used to scale the zero dimension based on the original image
  88. /// size.
  89. Size? size;
  90. /// Color to tint the image.
  91. Color? color;
  92. /// Check to see if the style object has a non-null, non-zero size.
  93. bool get hasDefinedSize => size != null && size!.longestSide > 0;
  94. @override
  95. int get hashCode => size.hashCode ^ color.hashCode;
  96. @override
  97. bool operator ==(Object other) {
  98. if (other is QrEmbeddedImageStyle) {
  99. return size == other.size && color == other.color;
  100. }
  101. return false;
  102. }
  103. }