[in_app_purchase] fix skerror nullability (#6139)

Should fix https://github.com/flutter/flutter/issues/143177
This commit is contained in:
LouiseHsu
2024-02-15 16:10:06 -08:00
committed by GitHub
parent dcbaee5389
commit cc05af82e2
8 changed files with 25 additions and 9 deletions

View File

@ -1,3 +1,7 @@
## 0.3.11
* Fixes SKError.userInfo not being nullable.
## 0.3.10 ## 0.3.10
* Converts `startProductRequest()`, `finishTransaction()`, `restoreTransactions()`, `presentCodeRedemptionSheet()` to pigeon. * Converts `startProductRequest()`, `finishTransaction()`, `restoreTransactions()`, `presentCodeRedemptionSheet()` to pigeon.

View File

@ -146,10 +146,10 @@ typedef NS_ENUM(NSUInteger, SKSubscriptionPeriodUnitMessage) {
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithCode:(NSInteger)code + (instancetype)makeWithCode:(NSInteger)code
domain:(NSString *)domain domain:(NSString *)domain
userInfo:(NSDictionary<NSString *, id> *)userInfo; userInfo:(nullable NSDictionary<NSString *, id> *)userInfo;
@property(nonatomic, assign) NSInteger code; @property(nonatomic, assign) NSInteger code;
@property(nonatomic, copy) NSString *domain; @property(nonatomic, copy) NSString *domain;
@property(nonatomic, copy) NSDictionary<NSString *, id> *userInfo; @property(nonatomic, copy, nullable) NSDictionary<NSString *, id> *userInfo;
@end @end
@interface SKPaymentDiscountMessage : NSObject @interface SKPaymentDiscountMessage : NSObject

View File

@ -218,7 +218,7 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
@implementation SKErrorMessage @implementation SKErrorMessage
+ (instancetype)makeWithCode:(NSInteger)code + (instancetype)makeWithCode:(NSInteger)code
domain:(NSString *)domain domain:(NSString *)domain
userInfo:(NSDictionary<NSString *, id> *)userInfo { userInfo:(nullable NSDictionary<NSString *, id> *)userInfo {
SKErrorMessage *pigeonResult = [[SKErrorMessage alloc] init]; SKErrorMessage *pigeonResult = [[SKErrorMessage alloc] init];
pigeonResult.code = code; pigeonResult.code = code;
pigeonResult.domain = domain; pigeonResult.domain = domain;

View File

@ -195,14 +195,14 @@ class SKErrorMessage {
SKErrorMessage({ SKErrorMessage({
required this.code, required this.code,
required this.domain, required this.domain,
required this.userInfo, this.userInfo,
}); });
int code; int code;
String domain; String domain;
Map<String?, Object?> userInfo; Map<String?, Object?>? userInfo;
Object encode() { Object encode() {
return <Object?>[ return <Object?>[
@ -217,7 +217,7 @@ class SKErrorMessage {
return SKErrorMessage( return SKErrorMessage(
code: result[0]! as int, code: result[0]! as int,
domain: result[1]! as String, domain: result[1]! as String,
userInfo: (result[2] as Map<Object?, Object?>?)!.cast<String?, Object?>(), userInfo: (result[2] as Map<Object?, Object?>?)?.cast<String?, Object?>(),
); );
} }
} }

View File

@ -380,7 +380,10 @@ class SKError {
/// Converts [SKErrorMessage] into the dart equivalent /// Converts [SKErrorMessage] into the dart equivalent
static SKError convertFromPigeon(SKErrorMessage msg) { static SKError convertFromPigeon(SKErrorMessage msg) {
return SKError(code: msg.code, domain: msg.domain, userInfo: msg.userInfo); return SKError(
code: msg.code,
domain: msg.domain,
userInfo: msg.userInfo ?? <String, Object>{});
} }
} }

View File

@ -91,7 +91,7 @@ class SKErrorMessage {
final int code; final int code;
final String domain; final String domain;
final Map<String?, Object?> userInfo; final Map<String?, Object?>? userInfo;
} }
class SKPaymentDiscountMessage { class SKPaymentDiscountMessage {

View File

@ -2,7 +2,7 @@ name: in_app_purchase_storekit
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework. description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.3.10 version: 0.3.11
environment: environment:
sdk: ^3.2.3 sdk: ^3.2.3

View File

@ -95,4 +95,13 @@ void main() {
SkProductResponseWrapper.convertFromPigeon(msg); SkProductResponseWrapper.convertFromPigeon(msg);
expect(convertedWrapper, productResponse); expect(convertedWrapper, productResponse);
}); });
test('test SKerror pigeon converter', () {
final SKErrorMessage msg = SKErrorMessage(code: 99, domain: 'domain');
final SKError wrapper = SKError.convertFromPigeon(msg);
expect(wrapper.code, 99);
expect(wrapper.domain, 'domain');
expect(wrapper.userInfo, <String, Object>{});
});
} }