Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class ApplePasskitPlugin: NSObject, FlutterPlugin {
private func getPasses(_ result: @escaping FlutterResult) {
let passNames = PKPassLibrary().passes().map {
return [
"passType": $0.passType,
"passType": String($0.passType.rawValue),
"serialNumber": $0.serialNumber,
"passTypeIdentifier": $0.passTypeIdentifier,
"deviceName": $0.deviceName,
"localizedName": $0.localizedName,
"localizedDescription": $0.localizedDescription,
"isRemotePass": $0.isRemotePass,
"passURL": $0.passURL?.absoluteString,
"passUrl": $0.passURL?.absoluteString,
"organizationName": $0.organizationName,
"icon": $0.icon.pngData(),
] as [String : Any?]
Expand Down
4 changes: 2 additions & 2 deletions apple_passkit/lib/src/apple_passkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class ApplePassKit {
/// return the same passes, but in a different order.
Future<List<ApplePkPass>> passes() async {
final list = await wrapWithException(
methodChannel.invokeMethod<List<Object>>(
methodChannel.invokeMethod<List<Object?>?>(
'getPasses',
),
);

return list
?.cast<Map<Object, Object?>>()
?.cast<Map<Object?, Object?>>()
.map(ApplePkPass.fromMap)
.toList() ??
[];
Expand Down
45 changes: 37 additions & 8 deletions apple_passkit/lib/src/apple_pk_pass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ApplePkPass {
required this.icon,
});

factory ApplePkPass.fromMap(Map<Object, Object?> map) {
factory ApplePkPass.fromMap(Map<Object?, Object?> map) {
return ApplePkPass(
passType: map['passType'] as String,
passType: PKPassType.fromJson(map['passType'] as String),
serialNumber: map['serialNumber'] as String,
passTypeIdentifier: map['passTypeIdentifier'] as String,
deviceName: map['deviceName'] as String,
Expand All @@ -29,7 +29,7 @@ class ApplePkPass {
}

/// The pass’s type.
final String passType;
final PKPassType passType;

/// A value that uniquely identifies the pass.
final String serialNumber;
Expand Down Expand Up @@ -61,13 +61,42 @@ class ApplePkPass {
}

/// Status after trying to add multiple passes.
enum PkPassType {
enum PKPassType {
Copy link
Owner

Choose a reason for hiding this comment

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

Even though the name more closely resembles the iOS name, this is a breaking change. I don't think we should do a bump of the major version for this fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you agree I will revert the name change, I think it is ok how it was before

Copy link
Owner

Choose a reason for hiding this comment

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

I've already done so

/// A nonspecific pass type.
any,
any('18446744073709551615'),

/// A pass that represents a barcode.
barcode,
barcode('0'),

/// A pass that represents a credential that the device stores in the Secure Element.
secureElement
}
secureElement('1'),

/// Deprecated, but maps to secureElement value
payment('1');

/// Constructor to initialize each enum case with a string representation of the integer value
const PKPassType(this.value);

/// A field to store the string value associated with each enum case (representing integers as strings)
final String value;

// Factory method to create an enum from a JSON value (string)
static PKPassType fromJson(String jsonValue) {
for (PKPassType type in PKPassType.values) {
if (type.value == jsonValue) {
return type;
}
}
throw ArgumentError('Invalid PKPassType value: $jsonValue');
Copy link
Owner

Choose a reason for hiding this comment

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

What do you think of falling back to any instead of throwing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is a good solution, it removes the necessity for exception handling.

}

// Method to convert the enum case back to a string for JSON serialization
String toJson() {
return value;
}

@override
String toString() {
return value; // Return the string representation of the integer value
}
}
Loading