Skip to content

Commit

Permalink
Merge pull request #1175 from navaronbracke/unknown_encryption_type
Browse files Browse the repository at this point in the history
fix: Handle unknown barcode data enum types & disable media controls
  • Loading branch information
navaronbracke authored Sep 9, 2024
2 parents c4bf426 + fe6be14 commit 23f3dd3
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 31 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 5.2.3

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.
* [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.

## 5.2.2

Improvements:
Expand Down
2 changes: 1 addition & 1 deletion ios/mobile_scanner.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/enums/address_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum AddressType {
case 2:
return AddressType.home;
default:
throw ArgumentError.value(value, 'value', 'Invalid raw value.');
return AddressType.unknown;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/enums/barcode_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enum BarcodeType {
case 12:
return BarcodeType.driverLicense;
default:
throw ArgumentError.value(value, 'value', 'Invalid raw value.');
return BarcodeType.unknown;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/enums/email_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum EmailType {
case 2:
return EmailType.home;
default:
throw ArgumentError.value(value, 'value', 'Invalid raw value.');
return EmailType.unknown;
}
}

Expand Down
11 changes: 8 additions & 3 deletions lib/src/enums/encryption_type.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Wifi encryption type constants.
enum EncryptionType {
/// Unknown encryption type.
none(0),
unknown(0),

/// Not encrypted.
open(1),
Expand All @@ -14,18 +14,23 @@ 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:
return EncryptionType.wpa;
case 3:
return EncryptionType.wep;
default:
throw ArgumentError.value(value, 'value', 'Invalid raw value.');
return EncryptionType.unknown;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/enums/phone_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum PhoneType {
case 4:
return PhoneType.mobile;
default:
throw ArgumentError.value(value, 'value', 'Invalid raw value.');
return PhoneType.unknown;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/wifi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
12 changes: 12 additions & 0 deletions lib/src/web/mobile_scanner_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion macos/mobile_scanner.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 3 additions & 3 deletions test/enums/address_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
6 changes: 3 additions & 3 deletions test/enums/barcode_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
6 changes: 3 additions & 3 deletions test/enums/email_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
13 changes: 5 additions & 8 deletions test/enums/encryption_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void main() {
group('$EncryptionType tests', () {
test('can be created from raw value', () {
const values = <int, EncryptionType>{
0: EncryptionType.none,
0: EncryptionType.unknown,
1: EncryptionType.open,
2: EncryptionType.wpa,
3: EncryptionType.wep,
Expand All @@ -18,20 +18,17 @@ 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(outOfRange),
throwsArgumentError,
);
expect(EncryptionType.fromRawValue(negative), EncryptionType.unknown);
expect(EncryptionType.fromRawValue(outOfRange), EncryptionType.unknown);
});

test('can be converted to raw value', () {
const values = <EncryptionType, int>{
EncryptionType.none: 0,
EncryptionType.unknown: 0,
EncryptionType.open: 1,
EncryptionType.wpa: 2,
EncryptionType.wep: 3,
Expand Down
6 changes: 3 additions & 3 deletions test/enums/phone_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit 23f3dd3

Please sign in to comment.