From 603410ae619895a78622b2202011481c2bf4723f Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 09:02:18 +0200 Subject: [PATCH 1/7] update existing enums that have an 'unknown' value to not throw on unrecognized values --- lib/src/enums/address_type.dart | 2 +- lib/src/enums/barcode_type.dart | 2 +- lib/src/enums/email_type.dart | 2 +- lib/src/enums/phone_type.dart | 2 +- test/enums/address_type_test.dart | 6 +++--- test/enums/barcode_type_test.dart | 6 +++--- test/enums/email_type_test.dart | 6 +++--- test/enums/phone_type_test.dart | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/src/enums/address_type.dart b/lib/src/enums/address_type.dart index 2f8de5ccf..e5266b6cf 100644 --- a/lib/src/enums/address_type.dart +++ b/lib/src/enums/address_type.dart @@ -20,7 +20,7 @@ enum AddressType { case 2: return AddressType.home; default: - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); + return AddressType.unknown; } } diff --git a/lib/src/enums/barcode_type.dart b/lib/src/enums/barcode_type.dart index 76fce7f99..559561e8f 100644 --- a/lib/src/enums/barcode_type.dart +++ b/lib/src/enums/barcode_type.dart @@ -70,7 +70,7 @@ enum BarcodeType { case 12: return BarcodeType.driverLicense; default: - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); + return BarcodeType.unknown; } } diff --git a/lib/src/enums/email_type.dart b/lib/src/enums/email_type.dart index b753cd8f1..f9a6be1c5 100644 --- a/lib/src/enums/email_type.dart +++ b/lib/src/enums/email_type.dart @@ -20,7 +20,7 @@ enum EmailType { case 2: return EmailType.home; default: - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); + return EmailType.unknown; } } diff --git a/lib/src/enums/phone_type.dart b/lib/src/enums/phone_type.dart index 81e684a96..8f51f08cf 100644 --- a/lib/src/enums/phone_type.dart +++ b/lib/src/enums/phone_type.dart @@ -30,7 +30,7 @@ enum PhoneType { case 4: return PhoneType.mobile; default: - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); + return PhoneType.unknown; } } diff --git a/test/enums/address_type_test.dart b/test/enums/address_type_test.dart index ec4a36f7c..31c900205 100644 --- a/test/enums/address_type_test.dart +++ b/test/enums/address_type_test.dart @@ -17,12 +17,12 @@ void main() { } }); - test('invalid raw value throws argument error', () { + test('invalid raw value returns AddressType.unknown', () { const int negative = -1; const int outOfRange = 3; - expect(() => AddressType.fromRawValue(negative), throwsArgumentError); - expect(() => AddressType.fromRawValue(outOfRange), throwsArgumentError); + expect(() => AddressType.fromRawValue(negative), AddressType.unknown); + expect(() => AddressType.fromRawValue(outOfRange), AddressType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/barcode_type_test.dart b/test/enums/barcode_type_test.dart index 0c0cb09a6..044fd7141 100644 --- a/test/enums/barcode_type_test.dart +++ b/test/enums/barcode_type_test.dart @@ -27,12 +27,12 @@ void main() { } }); - test('invalid raw value throws argument error', () { + test('invalid raw value returns BarcodeType.unknown', () { const int negative = -1; const int outOfRange = 13; - expect(() => BarcodeType.fromRawValue(negative), throwsArgumentError); - expect(() => BarcodeType.fromRawValue(outOfRange), throwsArgumentError); + expect(() => BarcodeType.fromRawValue(negative), BarcodeType.unknown); + expect(() => BarcodeType.fromRawValue(outOfRange), BarcodeType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/email_type_test.dart b/test/enums/email_type_test.dart index d83e6921c..0a0cc6891 100644 --- a/test/enums/email_type_test.dart +++ b/test/enums/email_type_test.dart @@ -17,12 +17,12 @@ void main() { } }); - test('invalid raw value throws argument error', () { + test('invalid raw value returns EmailType.unknown', () { const int negative = -1; const int outOfRange = 3; - expect(() => EmailType.fromRawValue(negative), throwsArgumentError); - expect(() => EmailType.fromRawValue(outOfRange), throwsArgumentError); + expect(() => EmailType.fromRawValue(negative), EmailType.unknown); + expect(() => EmailType.fromRawValue(outOfRange), EmailType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/phone_type_test.dart b/test/enums/phone_type_test.dart index f518a79f4..40a69487e 100644 --- a/test/enums/phone_type_test.dart +++ b/test/enums/phone_type_test.dart @@ -19,12 +19,12 @@ void main() { } }); - test('invalid raw value throws argument error', () { + test('invalid raw value returns PhoneType.unknown', () { const int negative = -1; const int outOfRange = 5; - expect(() => PhoneType.fromRawValue(negative), throwsArgumentError); - expect(() => PhoneType.fromRawValue(outOfRange), throwsArgumentError); + expect(() => PhoneType.fromRawValue(negative), PhoneType.unknown); + expect(() => PhoneType.fromRawValue(outOfRange), PhoneType.unknown); }); test('can be converted to raw value', () { From 065ddf83f0c613dcf3656bfc238b625a93f15087 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 09:18:27 +0200 Subject: [PATCH 2/7] deprecate EncryptionType.none; fallback to EncryptionType.unknown for unrecognized values --- lib/src/enums/encryption_type.dart | 9 ++++++--- lib/src/objects/wifi.dart | 2 +- test/enums/encryption_type_test.dart | 10 +++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/src/enums/encryption_type.dart b/lib/src/enums/encryption_type.dart index 7e9b3ca84..11fe26ae4 100644 --- a/lib/src/enums/encryption_type.dart +++ b/lib/src/enums/encryption_type.dart @@ -1,7 +1,7 @@ /// Wifi encryption type constants. enum EncryptionType { /// Unknown encryption type. - none(0), + unknown(0), /// Not encrypted. open(1), @@ -14,10 +14,13 @@ enum EncryptionType { const EncryptionType(this.rawValue); + @Deprecated('EncryptionType.none is deprecated. Use EncryptionType.unknown instead.') + static const EncryptionType none = EncryptionType.unknown; + factory EncryptionType.fromRawValue(int value) { switch (value) { case 0: - return EncryptionType.none; + return EncryptionType.unknown; case 1: return EncryptionType.open; case 2: @@ -25,7 +28,7 @@ enum EncryptionType { case 3: return EncryptionType.wep; default: - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); + return EncryptionType.unknown; } } diff --git a/lib/src/objects/wifi.dart b/lib/src/objects/wifi.dart index 2505e8f02..5dc295d33 100644 --- a/lib/src/objects/wifi.dart +++ b/lib/src/objects/wifi.dart @@ -5,7 +5,7 @@ import 'package:mobile_scanner/src/enums/encryption_type.dart'; class WiFi { /// Construct a new [WiFi] instance. const WiFi({ - this.encryptionType = EncryptionType.none, + this.encryptionType = EncryptionType.unknown, this.ssid, this.password, }); diff --git a/test/enums/encryption_type_test.dart b/test/enums/encryption_type_test.dart index ae8ae7b1e..8dd372e32 100644 --- a/test/enums/encryption_type_test.dart +++ b/test/enums/encryption_type_test.dart @@ -5,7 +5,7 @@ void main() { group('$EncryptionType tests', () { test('can be created from raw value', () { const values = { - 0: EncryptionType.none, + 0: EncryptionType.unknown, 1: EncryptionType.open, 2: EncryptionType.wpa, 3: EncryptionType.wep, @@ -18,20 +18,20 @@ void main() { } }); - test('invalid raw value throws argument error', () { + test('invalid raw value returns EncryptionType.unknown', () { const int negative = -1; const int outOfRange = 4; - expect(() => EncryptionType.fromRawValue(negative), throwsArgumentError); + expect(() => EncryptionType.fromRawValue(negative), EncryptionType.unknown); expect( () => EncryptionType.fromRawValue(outOfRange), - throwsArgumentError, + EncryptionType.unknown, ); }); test('can be converted to raw value', () { const values = { - EncryptionType.none: 0, + EncryptionType.unknown: 0, EncryptionType.open: 1, EncryptionType.wpa: 2, EncryptionType.wep: 3, From bb8a1235cb3045b2b05c5b56a70f1091b7e25aed Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 09:26:25 +0200 Subject: [PATCH 3/7] fix test expectations; fix missing comma --- lib/src/enums/encryption_type.dart | 4 +++- test/enums/address_type_test.dart | 4 ++-- test/enums/barcode_type_test.dart | 4 ++-- test/enums/email_type_test.dart | 4 ++-- test/enums/encryption_type_test.dart | 7 ++----- test/enums/phone_type_test.dart | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/src/enums/encryption_type.dart b/lib/src/enums/encryption_type.dart index 11fe26ae4..65624591b 100644 --- a/lib/src/enums/encryption_type.dart +++ b/lib/src/enums/encryption_type.dart @@ -14,7 +14,9 @@ enum EncryptionType { const EncryptionType(this.rawValue); - @Deprecated('EncryptionType.none is deprecated. Use EncryptionType.unknown instead.') + @Deprecated( + 'EncryptionType.none is deprecated. Use EncryptionType.unknown instead.', + ) static const EncryptionType none = EncryptionType.unknown; factory EncryptionType.fromRawValue(int value) { diff --git a/test/enums/address_type_test.dart b/test/enums/address_type_test.dart index 31c900205..3c8913a38 100644 --- a/test/enums/address_type_test.dart +++ b/test/enums/address_type_test.dart @@ -21,8 +21,8 @@ void main() { const int negative = -1; const int outOfRange = 3; - expect(() => AddressType.fromRawValue(negative), AddressType.unknown); - expect(() => AddressType.fromRawValue(outOfRange), AddressType.unknown); + expect(AddressType.fromRawValue(negative), AddressType.unknown); + expect(AddressType.fromRawValue(outOfRange), AddressType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/barcode_type_test.dart b/test/enums/barcode_type_test.dart index 044fd7141..7d9f762fc 100644 --- a/test/enums/barcode_type_test.dart +++ b/test/enums/barcode_type_test.dart @@ -31,8 +31,8 @@ void main() { const int negative = -1; const int outOfRange = 13; - expect(() => BarcodeType.fromRawValue(negative), BarcodeType.unknown); - expect(() => BarcodeType.fromRawValue(outOfRange), BarcodeType.unknown); + expect(BarcodeType.fromRawValue(negative), BarcodeType.unknown); + expect(BarcodeType.fromRawValue(outOfRange), BarcodeType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/email_type_test.dart b/test/enums/email_type_test.dart index 0a0cc6891..b69a49a8c 100644 --- a/test/enums/email_type_test.dart +++ b/test/enums/email_type_test.dart @@ -21,8 +21,8 @@ void main() { const int negative = -1; const int outOfRange = 3; - expect(() => EmailType.fromRawValue(negative), EmailType.unknown); - expect(() => EmailType.fromRawValue(outOfRange), EmailType.unknown); + expect(EmailType.fromRawValue(negative), EmailType.unknown); + expect(EmailType.fromRawValue(outOfRange), EmailType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/encryption_type_test.dart b/test/enums/encryption_type_test.dart index 8dd372e32..30a788801 100644 --- a/test/enums/encryption_type_test.dart +++ b/test/enums/encryption_type_test.dart @@ -22,11 +22,8 @@ void main() { const int negative = -1; const int outOfRange = 4; - expect(() => EncryptionType.fromRawValue(negative), EncryptionType.unknown); - expect( - () => EncryptionType.fromRawValue(outOfRange), - EncryptionType.unknown, - ); + expect(EncryptionType.fromRawValue(negative), EncryptionType.unknown); + expect(EncryptionType.fromRawValue(outOfRange), EncryptionType.unknown); }); test('can be converted to raw value', () { diff --git a/test/enums/phone_type_test.dart b/test/enums/phone_type_test.dart index 40a69487e..f19c6a5a7 100644 --- a/test/enums/phone_type_test.dart +++ b/test/enums/phone_type_test.dart @@ -23,8 +23,8 @@ void main() { const int negative = -1; const int outOfRange = 5; - expect(() => PhoneType.fromRawValue(negative), PhoneType.unknown); - expect(() => PhoneType.fromRawValue(outOfRange), PhoneType.unknown); + expect(PhoneType.fromRawValue(negative), PhoneType.unknown); + expect(PhoneType.fromRawValue(outOfRange), PhoneType.unknown); }); test('can be converted to raw value', () { From 5595bf0ace32c2b62f276409005bc4cb7f22a67f Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 09:32:52 +0200 Subject: [PATCH 4/7] update changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff9d4a1f4..79f4f93fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## NEXT + +Deprecations: +* The `EncryptionType.none` constant has been deprecated, as its name was misleading. Use `EncryptionType.unknown` instead. + +Bugs fixed: +* Fixed `EncryptionType` throwing on invalid `SAE` encryption type. + +Improvements: +* All enum types for barcode data (i.e. Wifi type or email type) now return `unknown` for unrecognized values. + ## 5.2.2 Improvements: From 6b07dc008123bc4eb575479bc76e3a65e631915f Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 09:39:24 +0200 Subject: [PATCH 5/7] bump version --- CHANGELOG.md | 2 +- ios/mobile_scanner.podspec | 2 +- macos/mobile_scanner.podspec | 2 +- pubspec.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f4f93fc..81b940150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## NEXT +## 5.2.3 Deprecations: * The `EncryptionType.none` constant has been deprecated, as its name was misleading. Use `EncryptionType.unknown` instead. diff --git a/ios/mobile_scanner.podspec b/ios/mobile_scanner.podspec index 61dd8e6b1..cff74e2bc 100644 --- a/ios/mobile_scanner.podspec +++ b/ios/mobile_scanner.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'mobile_scanner' - s.version = '5.2.2' + s.version = '5.2.3' s.summary = 'An universal scanner for Flutter based on MLKit.' s.description = <<-DESC An universal scanner for Flutter based on MLKit. diff --git a/macos/mobile_scanner.podspec b/macos/mobile_scanner.podspec index 2e5e5122b..94d5a7cda 100644 --- a/macos/mobile_scanner.podspec +++ b/macos/mobile_scanner.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'mobile_scanner' - s.version = '5.2.2' + s.version = '5.2.3' s.summary = 'An universal scanner for Flutter based on MLKit.' s.description = <<-DESC An universal scanner for Flutter based on MLKit. diff --git a/pubspec.yaml b/pubspec.yaml index 4997e7909..80cdce43e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mobile_scanner 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. -version: 5.2.2 +version: 5.2.3 repository: https://github.com/juliansteenbakker/mobile_scanner screenshots: From 9febbe88734bb0b68d7f1dfefeed1bdfcf262266 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 12:34:20 +0200 Subject: [PATCH 6/7] do not show controls on video element --- lib/src/web/mobile_scanner_web.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/web/mobile_scanner_web.dart b/lib/src/web/mobile_scanner_web.dart index e3ada8c8d..963c13d87 100644 --- a/lib/src/web/mobile_scanner_web.dart +++ b/lib/src/web/mobile_scanner_web.dart @@ -88,6 +88,18 @@ class MobileScannerWeb extends MobileScannerPlatform { ..transformOrigin = 'center' ..pointerEvents = 'none'; + // Do not show the media controls, as this is a preview element. + // Also prevent play/pause events from changing the media controls. + videoElement.controls = false; + + videoElement.onplay = (JSAny _) { + videoElement.controls = false; + }.toJS; + + videoElement.onpause = (JSAny _) { + videoElement.controls = false; + }.toJS; + // Attach the video element to its parent container // and setup the PlatformView factory for this `textureId`. _divElement = HTMLDivElement() From fe6be141da2caf830fc62957db636bc919220c30 Mon Sep 17 00:00:00 2001 From: Navaron Bracke Date: Mon, 9 Sep 2024 12:36:37 +0200 Subject: [PATCH 7/7] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b940150..412a20625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Deprecations: Bugs fixed: * Fixed `EncryptionType` throwing on invalid `SAE` encryption type. +* [web] Removed the `controls` attribute on the video preview. Improvements: * All enum types for barcode data (i.e. Wifi type or email type) now return `unknown` for unrecognized values.