Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
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),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in #1172

Android: never reported 'none/unknown'
iOS: reported MLKBarcodeWiFiEncryptionTypeUnknown as integer 0

So this constant's name is wrong, but the documentation is correct. I opted into deprecating the old name (providing a static const for users to migrate), to match the new, correct behavior.


/// 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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backwards compatibility, Included a static const alias that points to the old name.

We can remove this constant in version 6.0.0


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.');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the strange integer 4 that was reported in #1172

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
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
Loading