Navaron Bracke
Committed by GitHub

Merge pull request #1175 from navaronbracke/unknown_encryption_type

fix: Handle unknown barcode data enum types & disable media controls
  1 +## 5.2.3
  2 +
  3 +Deprecations:
  4 +* The `EncryptionType.none` constant has been deprecated, as its name was misleading. Use `EncryptionType.unknown` instead.
  5 +
  6 +Bugs fixed:
  7 +* Fixed `EncryptionType` throwing on invalid `SAE` encryption type.
  8 +* [web] Removed the `controls` attribute on the video preview.
  9 +
  10 +Improvements:
  11 +* All enum types for barcode data (i.e. Wifi type or email type) now return `unknown` for unrecognized values.
  12 +
1 ## 5.2.2 13 ## 5.2.2
2 14
3 Improvements: 15 Improvements:
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 # 4 #
5 Pod::Spec.new do |s| 5 Pod::Spec.new do |s|
6 s.name = 'mobile_scanner' 6 s.name = 'mobile_scanner'
7 - s.version = '5.2.2' 7 + s.version = '5.2.3'
8 s.summary = 'An universal scanner for Flutter based on MLKit.' 8 s.summary = 'An universal scanner for Flutter based on MLKit.'
9 s.description = <<-DESC 9 s.description = <<-DESC
10 An universal scanner for Flutter based on MLKit. 10 An universal scanner for Flutter based on MLKit.
@@ -20,7 +20,7 @@ enum AddressType { @@ -20,7 +20,7 @@ enum AddressType {
20 case 2: 20 case 2:
21 return AddressType.home; 21 return AddressType.home;
22 default: 22 default:
23 - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); 23 + return AddressType.unknown;
24 } 24 }
25 } 25 }
26 26
@@ -70,7 +70,7 @@ enum BarcodeType { @@ -70,7 +70,7 @@ enum BarcodeType {
70 case 12: 70 case 12:
71 return BarcodeType.driverLicense; 71 return BarcodeType.driverLicense;
72 default: 72 default:
73 - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); 73 + return BarcodeType.unknown;
74 } 74 }
75 } 75 }
76 76
@@ -20,7 +20,7 @@ enum EmailType { @@ -20,7 +20,7 @@ enum EmailType {
20 case 2: 20 case 2:
21 return EmailType.home; 21 return EmailType.home;
22 default: 22 default:
23 - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); 23 + return EmailType.unknown;
24 } 24 }
25 } 25 }
26 26
1 /// Wifi encryption type constants. 1 /// Wifi encryption type constants.
2 enum EncryptionType { 2 enum EncryptionType {
3 /// Unknown encryption type. 3 /// Unknown encryption type.
4 - none(0), 4 + unknown(0),
5 5
6 /// Not encrypted. 6 /// Not encrypted.
7 open(1), 7 open(1),
@@ -14,10 +14,15 @@ enum EncryptionType { @@ -14,10 +14,15 @@ enum EncryptionType {
14 14
15 const EncryptionType(this.rawValue); 15 const EncryptionType(this.rawValue);
16 16
  17 + @Deprecated(
  18 + 'EncryptionType.none is deprecated. Use EncryptionType.unknown instead.',
  19 + )
  20 + static const EncryptionType none = EncryptionType.unknown;
  21 +
17 factory EncryptionType.fromRawValue(int value) { 22 factory EncryptionType.fromRawValue(int value) {
18 switch (value) { 23 switch (value) {
19 case 0: 24 case 0:
20 - return EncryptionType.none; 25 + return EncryptionType.unknown;
21 case 1: 26 case 1:
22 return EncryptionType.open; 27 return EncryptionType.open;
23 case 2: 28 case 2:
@@ -25,7 +30,7 @@ enum EncryptionType { @@ -25,7 +30,7 @@ enum EncryptionType {
25 case 3: 30 case 3:
26 return EncryptionType.wep; 31 return EncryptionType.wep;
27 default: 32 default:
28 - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); 33 + return EncryptionType.unknown;
29 } 34 }
30 } 35 }
31 36
@@ -30,7 +30,7 @@ enum PhoneType { @@ -30,7 +30,7 @@ enum PhoneType {
30 case 4: 30 case 4:
31 return PhoneType.mobile; 31 return PhoneType.mobile;
32 default: 32 default:
33 - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); 33 + return PhoneType.unknown;
34 } 34 }
35 } 35 }
36 36
@@ -5,7 +5,7 @@ import 'package:mobile_scanner/src/enums/encryption_type.dart'; @@ -5,7 +5,7 @@ import 'package:mobile_scanner/src/enums/encryption_type.dart';
5 class WiFi { 5 class WiFi {
6 /// Construct a new [WiFi] instance. 6 /// Construct a new [WiFi] instance.
7 const WiFi({ 7 const WiFi({
8 - this.encryptionType = EncryptionType.none, 8 + this.encryptionType = EncryptionType.unknown,
9 this.ssid, 9 this.ssid,
10 this.password, 10 this.password,
11 }); 11 });
@@ -88,6 +88,18 @@ class MobileScannerWeb extends MobileScannerPlatform { @@ -88,6 +88,18 @@ class MobileScannerWeb extends MobileScannerPlatform {
88 ..transformOrigin = 'center' 88 ..transformOrigin = 'center'
89 ..pointerEvents = 'none'; 89 ..pointerEvents = 'none';
90 90
  91 + // Do not show the media controls, as this is a preview element.
  92 + // Also prevent play/pause events from changing the media controls.
  93 + videoElement.controls = false;
  94 +
  95 + videoElement.onplay = (JSAny _) {
  96 + videoElement.controls = false;
  97 + }.toJS;
  98 +
  99 + videoElement.onpause = (JSAny _) {
  100 + videoElement.controls = false;
  101 + }.toJS;
  102 +
91 // Attach the video element to its parent container 103 // Attach the video element to its parent container
92 // and setup the PlatformView factory for this `textureId`. 104 // and setup the PlatformView factory for this `textureId`.
93 _divElement = HTMLDivElement() 105 _divElement = HTMLDivElement()
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 # 4 #
5 Pod::Spec.new do |s| 5 Pod::Spec.new do |s|
6 s.name = 'mobile_scanner' 6 s.name = 'mobile_scanner'
7 - s.version = '5.2.2' 7 + s.version = '5.2.3'
8 s.summary = 'An universal scanner for Flutter based on MLKit.' 8 s.summary = 'An universal scanner for Flutter based on MLKit.'
9 s.description = <<-DESC 9 s.description = <<-DESC
10 An universal scanner for Flutter based on MLKit. 10 An universal scanner for Flutter based on MLKit.
1 name: mobile_scanner 1 name: mobile_scanner
2 description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS. 2 description: A universal barcode and QR code scanner for Flutter based on MLKit. Uses CameraX on Android, AVFoundation on iOS and Apple Vision & AVFoundation on macOS.
3 -version: 5.2.2 3 +version: 5.2.3
4 repository: https://github.com/juliansteenbakker/mobile_scanner 4 repository: https://github.com/juliansteenbakker/mobile_scanner
5 5
6 screenshots: 6 screenshots:
@@ -17,12 +17,12 @@ void main() { @@ -17,12 +17,12 @@ void main() {
17 } 17 }
18 }); 18 });
19 19
20 - test('invalid raw value throws argument error', () { 20 + test('invalid raw value returns AddressType.unknown', () {
21 const int negative = -1; 21 const int negative = -1;
22 const int outOfRange = 3; 22 const int outOfRange = 3;
23 23
24 - expect(() => AddressType.fromRawValue(negative), throwsArgumentError);  
25 - expect(() => AddressType.fromRawValue(outOfRange), throwsArgumentError); 24 + expect(AddressType.fromRawValue(negative), AddressType.unknown);
  25 + expect(AddressType.fromRawValue(outOfRange), AddressType.unknown);
26 }); 26 });
27 27
28 test('can be converted to raw value', () { 28 test('can be converted to raw value', () {
@@ -27,12 +27,12 @@ void main() { @@ -27,12 +27,12 @@ void main() {
27 } 27 }
28 }); 28 });
29 29
30 - test('invalid raw value throws argument error', () { 30 + test('invalid raw value returns BarcodeType.unknown', () {
31 const int negative = -1; 31 const int negative = -1;
32 const int outOfRange = 13; 32 const int outOfRange = 13;
33 33
34 - expect(() => BarcodeType.fromRawValue(negative), throwsArgumentError);  
35 - expect(() => BarcodeType.fromRawValue(outOfRange), throwsArgumentError); 34 + expect(BarcodeType.fromRawValue(negative), BarcodeType.unknown);
  35 + expect(BarcodeType.fromRawValue(outOfRange), BarcodeType.unknown);
36 }); 36 });
37 37
38 test('can be converted to raw value', () { 38 test('can be converted to raw value', () {
@@ -17,12 +17,12 @@ void main() { @@ -17,12 +17,12 @@ void main() {
17 } 17 }
18 }); 18 });
19 19
20 - test('invalid raw value throws argument error', () { 20 + test('invalid raw value returns EmailType.unknown', () {
21 const int negative = -1; 21 const int negative = -1;
22 const int outOfRange = 3; 22 const int outOfRange = 3;
23 23
24 - expect(() => EmailType.fromRawValue(negative), throwsArgumentError);  
25 - expect(() => EmailType.fromRawValue(outOfRange), throwsArgumentError); 24 + expect(EmailType.fromRawValue(negative), EmailType.unknown);
  25 + expect(EmailType.fromRawValue(outOfRange), EmailType.unknown);
26 }); 26 });
27 27
28 test('can be converted to raw value', () { 28 test('can be converted to raw value', () {
@@ -5,7 +5,7 @@ void main() { @@ -5,7 +5,7 @@ void main() {
5 group('$EncryptionType tests', () { 5 group('$EncryptionType tests', () {
6 test('can be created from raw value', () { 6 test('can be created from raw value', () {
7 const values = <int, EncryptionType>{ 7 const values = <int, EncryptionType>{
8 - 0: EncryptionType.none, 8 + 0: EncryptionType.unknown,
9 1: EncryptionType.open, 9 1: EncryptionType.open,
10 2: EncryptionType.wpa, 10 2: EncryptionType.wpa,
11 3: EncryptionType.wep, 11 3: EncryptionType.wep,
@@ -18,20 +18,17 @@ void main() { @@ -18,20 +18,17 @@ void main() {
18 } 18 }
19 }); 19 });
20 20
21 - test('invalid raw value throws argument error', () { 21 + test('invalid raw value returns EncryptionType.unknown', () {
22 const int negative = -1; 22 const int negative = -1;
23 const int outOfRange = 4; 23 const int outOfRange = 4;
24 24
25 - expect(() => EncryptionType.fromRawValue(negative), throwsArgumentError);  
26 - expect(  
27 - () => EncryptionType.fromRawValue(outOfRange),  
28 - throwsArgumentError,  
29 - ); 25 + expect(EncryptionType.fromRawValue(negative), EncryptionType.unknown);
  26 + expect(EncryptionType.fromRawValue(outOfRange), EncryptionType.unknown);
30 }); 27 });
31 28
32 test('can be converted to raw value', () { 29 test('can be converted to raw value', () {
33 const values = <EncryptionType, int>{ 30 const values = <EncryptionType, int>{
34 - EncryptionType.none: 0, 31 + EncryptionType.unknown: 0,
35 EncryptionType.open: 1, 32 EncryptionType.open: 1,
36 EncryptionType.wpa: 2, 33 EncryptionType.wpa: 2,
37 EncryptionType.wep: 3, 34 EncryptionType.wep: 3,
@@ -19,12 +19,12 @@ void main() { @@ -19,12 +19,12 @@ void main() {
19 } 19 }
20 }); 20 });
21 21
22 - test('invalid raw value throws argument error', () { 22 + test('invalid raw value returns PhoneType.unknown', () {
23 const int negative = -1; 23 const int negative = -1;
24 const int outOfRange = 5; 24 const int outOfRange = 5;
25 25
26 - expect(() => PhoneType.fromRawValue(negative), throwsArgumentError);  
27 - expect(() => PhoneType.fromRawValue(outOfRange), throwsArgumentError); 26 + expect(PhoneType.fromRawValue(negative), PhoneType.unknown);
  27 + expect(PhoneType.fromRawValue(outOfRange), PhoneType.unknown);
28 }); 28 });
29 29
30 test('can be converted to raw value', () { 30 test('can be converted to raw value', () {