From 7307390cde929c953de71f141f4ef96aa6c02192 Mon Sep 17 00:00:00 2001 From: Pedro Morais Date: Thu, 28 Nov 2024 17:16:30 +0000 Subject: [PATCH 1/2] fix: exceptions happening when trying to get passes --- apple_passkit/.vscode/settings.json | 29 ++++++------ .../apple_passkit/ApplePasskitPlugin.swift | 4 +- apple_passkit/lib/src/apple_passkit.dart | 4 +- apple_passkit/lib/src/apple_pk_pass.dart | 45 +++++++++++++++---- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/apple_passkit/.vscode/settings.json b/apple_passkit/.vscode/settings.json index 0b15a62..c06be2d 100644 --- a/apple_passkit/.vscode/settings.json +++ b/apple_passkit/.vscode/settings.json @@ -1,15 +1,16 @@ { - "dart.flutterTestAdditionalArgs": [], - "explorer.fileNesting.enabled": true, - "explorer.fileNesting.expand": true, - "explorer.fileNesting.patterns": { - "*.dart": "$(capture).*.dart", - "pubspec.yaml": "pubspec.lock,l10n.yaml,.packages,.metadata,analysis_options.yaml,.flutter-plugins,.flutter-plugins-dependencies,pubspec_overrides.yaml" - }, - "editor.codeActionsOnSave": { - "source.organizeImports": "explicit", - "source.fixAll": "explicit" - }, - "editor.formatOnSave": true, - "files.insertFinalNewline": true -} + "dart.flutterTestAdditionalArgs": [], + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.expand": true, + "explorer.fileNesting.patterns": { + "*.dart": "$(capture).*.dart", + "pubspec.yaml": "pubspec.lock,l10n.yaml,.packages,.metadata,analysis_options.yaml,.flutter-plugins,.flutter-plugins-dependencies,pubspec_overrides.yaml" + }, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit", + "source.fixAll": "explicit" + }, + "editor.formatOnSave": true, + "files.insertFinalNewline": true, + "dart.flutterSdkPath": ".fvm/versions/3.24.3" +} \ No newline at end of file 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 From 430bb6168626c84521cf6dd7d80a19a34631d09b Mon Sep 17 00:00:00 2001 From: Pedro Morais Date: Thu, 28 Nov 2024 17:28:28 +0000 Subject: [PATCH 2/2] chore: reset .vscode/settings.json --- apple_passkit/.vscode/settings.json | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/apple_passkit/.vscode/settings.json b/apple_passkit/.vscode/settings.json index c06be2d..0b15a62 100644 --- a/apple_passkit/.vscode/settings.json +++ b/apple_passkit/.vscode/settings.json @@ -1,16 +1,15 @@ { - "dart.flutterTestAdditionalArgs": [], - "explorer.fileNesting.enabled": true, - "explorer.fileNesting.expand": true, - "explorer.fileNesting.patterns": { - "*.dart": "$(capture).*.dart", - "pubspec.yaml": "pubspec.lock,l10n.yaml,.packages,.metadata,analysis_options.yaml,.flutter-plugins,.flutter-plugins-dependencies,pubspec_overrides.yaml" - }, - "editor.codeActionsOnSave": { - "source.organizeImports": "explicit", - "source.fixAll": "explicit" - }, - "editor.formatOnSave": true, - "files.insertFinalNewline": true, - "dart.flutterSdkPath": ".fvm/versions/3.24.3" -} \ No newline at end of file + "dart.flutterTestAdditionalArgs": [], + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.expand": true, + "explorer.fileNesting.patterns": { + "*.dart": "$(capture).*.dart", + "pubspec.yaml": "pubspec.lock,l10n.yaml,.packages,.metadata,analysis_options.yaml,.flutter-plugins,.flutter-plugins-dependencies,pubspec_overrides.yaml" + }, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit", + "source.fixAll": "explicit" + }, + "editor.formatOnSave": true, + "files.insertFinalNewline": true +}