diff --git a/apple_passkit/ios/apple_passkit/Sources/apple_passkit/ApplePasskitPlugin.swift b/apple_passkit/ios/apple_passkit/Sources/apple_passkit/ApplePasskitPlugin.swift index 00d458e..6e17b35 100644 --- a/apple_passkit/ios/apple_passkit/Sources/apple_passkit/ApplePasskitPlugin.swift +++ b/apple_passkit/ios/apple_passkit/Sources/apple_passkit/ApplePasskitPlugin.swift @@ -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?] diff --git a/apple_passkit/lib/src/apple_passkit.dart b/apple_passkit/lib/src/apple_passkit.dart index 81fe670..ee1ec3e 100644 --- a/apple_passkit/lib/src/apple_passkit.dart +++ b/apple_passkit/lib/src/apple_passkit.dart @@ -72,13 +72,13 @@ class ApplePassKit { /// return the same passes, but in a different order. Future> passes() async { final list = await wrapWithException( - methodChannel.invokeMethod>( + methodChannel.invokeMethod?>( 'getPasses', ), ); return list - ?.cast>() + ?.cast>() .map(ApplePkPass.fromMap) .toList() ?? []; diff --git a/apple_passkit/lib/src/apple_pk_pass.dart b/apple_passkit/lib/src/apple_pk_pass.dart index 0cecce4..bd2e1a8 100644 --- a/apple_passkit/lib/src/apple_pk_pass.dart +++ b/apple_passkit/lib/src/apple_pk_pass.dart @@ -13,9 +13,9 @@ class ApplePkPass { required this.icon, }); - factory ApplePkPass.fromMap(Map map) { + factory ApplePkPass.fromMap(Map 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, @@ -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; @@ -61,13 +61,42 @@ class ApplePkPass { } /// Status after trying to add multiple passes. -enum PkPassType { +enum PKPassType { /// 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'); + } + + // 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 + } +} \ No newline at end of file