Skip to content

Commit e742a7b

Browse files
authored
[in_app_purchase] Expose the NSLocale object (flutter#3897)
* Expose remaining "simple" fields from NSLocale on SKProductWrapper. * Fix tests * Fix serialization * Format code * Updated version and changelog * Revert "Updated version and changelog" This reverts commit 07fe2f5. * Updated version and changelog
1 parent 47b2a96 commit e742a7b

File tree

7 files changed

+286
-26
lines changed

7 files changed

+286
-26
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.1
2+
3+
* Exposed most of the NSLocale object via the SKProductWrapper class.
4+
15
## 0.1.0
26

37
* Initial open-source release.

packages/in_app_purchase/in_app_purchase_ios/ios/Classes/FIAObjectTranslator.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,38 @@ + (NSDictionary *)getMapFromNSLocale:(NSLocale *)locale {
107107
return nil;
108108
}
109109
NSMutableDictionary *map = [[NSMutableDictionary alloc] init];
110+
111+
[map setObject:[locale objectForKey:NSLocaleIdentifier] ?: [NSNull null]
112+
forKey:@"localeIdentifier"];
113+
[map setObject:[locale objectForKey:NSLocaleCountryCode] ?: [NSNull null] forKey:@"countryCode"];
114+
[map setObject:[locale objectForKey:NSLocaleLanguageCode] ?: [NSNull null]
115+
forKey:@"languageCode"];
116+
[map setObject:[locale objectForKey:NSLocaleScriptCode] ?: [NSNull null] forKey:@"scriptCode"];
117+
[map setObject:[locale objectForKey:NSLocaleVariantCode] ?: [NSNull null] forKey:@"variantCode"];
118+
[map setObject:[locale objectForKey:NSLocaleCollationIdentifier] ?: [NSNull null]
119+
forKey:@"collationIdentifier"];
120+
[map setObject:[locale objectForKey:NSLocaleCollatorIdentifier] ?: [NSNull null]
121+
forKey:@"collatorIdentifier"];
122+
[map setObject:[locale objectForKey:NSLocaleUsesMetricSystem] ?: [NSNull null]
123+
forKey:@"usesMetricSystem"];
124+
[map setObject:[locale objectForKey:NSLocaleMeasurementSystem] ?: [NSNull null]
125+
forKey:@"measurementSystem"];
126+
[map setObject:[locale objectForKey:NSLocaleDecimalSeparator] ?: [NSNull null]
127+
forKey:@"decimalSeparator"];
128+
[map setObject:[locale objectForKey:NSLocaleGroupingSeparator] ?: [NSNull null]
129+
forKey:@"groupingSeparator"];
110130
[map setObject:[locale objectForKey:NSLocaleCurrencySymbol] ?: [NSNull null]
111131
forKey:@"currencySymbol"];
112132
[map setObject:[locale objectForKey:NSLocaleCurrencyCode] ?: [NSNull null]
113133
forKey:@"currencyCode"];
134+
[map setObject:[locale objectForKey:NSLocaleQuotationEndDelimiterKey] ?: [NSNull null]
135+
forKey:@"endDelimiterKey"];
136+
[map setObject:[locale objectForKey:NSLocaleQuotationBeginDelimiterKey] ?: [NSNull null]
137+
forKey:@"beginDelimiterKey"];
138+
[map setObject:[locale objectForKey:NSLocaleAlternateQuotationEndDelimiterKey] ?: [NSNull null]
139+
forKey:@"alternateQuotationEndDelimiterKey"];
140+
[map setObject:[locale objectForKey:NSLocaleAlternateQuotationBeginDelimiterKey] ?: [NSNull null]
141+
forKey:@"alternateQuotationBeginDelimiterKey"];
114142
return map;
115143
}
116144

packages/in_app_purchase/in_app_purchase_ios/lib/src/store_kit_wrappers/sk_product_wrapper.dart

Lines changed: 140 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,25 +329,102 @@ class SKProductWrapper {
329329
/// Object that indicates the locale of the price
330330
///
331331
/// It is a thin wrapper of [NSLocale](https://developer.apple.com/documentation/foundation/nslocale?language=objc).
332-
// TODO(cyanglaz): NSLocale is a complex object, want to see the actual need of getting this expanded.
333-
// Matching android to only get the currencySymbol for now.
334-
// https://github.com/flutter/flutter/issues/26610
335332
@JsonSerializable()
336333
class SKPriceLocaleWrapper {
337334
/// Creates a new price locale for `currencySymbol` and `currencyCode`.
338-
SKPriceLocaleWrapper(
339-
{required this.currencySymbol, required this.currencyCode});
335+
SKPriceLocaleWrapper({
336+
required this.localeIdentifier,
337+
required this.countryCode,
338+
required this.languageCode,
339+
required this.scriptCode,
340+
required this.variantCode,
341+
required this.collationIdentifier,
342+
required this.collatorIdentifier,
343+
required this.usesMetricSystem,
344+
required this.measurementSystem,
345+
required this.decimalSeparator,
346+
required this.groupingSeparator,
347+
required this.currencySymbol,
348+
required this.currencyCode,
349+
required this.endDelimiterKey,
350+
required this.beginDelimiterKey,
351+
required this.alternateQuotationEndDelimiterKey,
352+
required this.alternateQuotationBeginDelimiterKey,
353+
});
340354

341355
/// Constructing an instance from a map from the Objective-C layer.
342356
///
343357
/// This method should only be used with `map` values returned by [SKProductWrapper.fromJson] and [SKProductDiscountWrapper.fromJson].
344358
factory SKPriceLocaleWrapper.fromJson(Map<String, dynamic>? map) {
345359
if (map == null) {
346-
return SKPriceLocaleWrapper(currencyCode: '', currencySymbol: '');
360+
return SKPriceLocaleWrapper(
361+
localeIdentifier: '',
362+
countryCode: '',
363+
languageCode: '',
364+
scriptCode: '',
365+
variantCode: '',
366+
collationIdentifier: '',
367+
collatorIdentifier: '',
368+
usesMetricSystem: true,
369+
measurementSystem: '',
370+
decimalSeparator: '',
371+
groupingSeparator: '',
372+
currencySymbol: '',
373+
currencyCode: '',
374+
endDelimiterKey: '',
375+
beginDelimiterKey: '',
376+
alternateQuotationEndDelimiterKey: '',
377+
alternateQuotationBeginDelimiterKey: '',
378+
);
347379
}
348380
return _$SKPriceLocaleWrapperFromJson(map);
349381
}
350382

383+
///The identifier for the locale, e.g. "en_US" for US locale.
384+
@JsonKey(defaultValue: '')
385+
final String localeIdentifier;
386+
387+
///The country or region code for the locale, e.g. "US" for en_US locale.
388+
@JsonKey(defaultValue: '')
389+
final String countryCode;
390+
391+
///The language code for the locale, e.g. "en" for en_US locale.
392+
@JsonKey(defaultValue: '')
393+
final String languageCode;
394+
395+
///The script code for the locale, e.g. "Latn" for en_US locale.
396+
@JsonKey(defaultValue: '')
397+
final String scriptCode;
398+
399+
///The variant code for the locale, e.g. "POSIX".
400+
@JsonKey(defaultValue: '')
401+
final String variantCode;
402+
403+
///The collation associated with the locale, e.g. "pinyin".
404+
@JsonKey(defaultValue: '')
405+
final String collationIdentifier;
406+
407+
///The collation identifier for the locale, e.g. "en".
408+
@JsonKey(defaultValue: '')
409+
final String collatorIdentifier;
410+
411+
///A flag whether the locale uses the metric system.
412+
///If the value is false, you can typically assume American measurement units (e.g. miles).
413+
@JsonKey(defaultValue: true)
414+
final bool usesMetricSystem;
415+
416+
///The measurement associated with the locale, e.g. "Metric" or "U.S.".
417+
@JsonKey(defaultValue: '')
418+
final String measurementSystem;
419+
420+
///The decimal separator associated with the locale, e.g. "." or ",".
421+
@JsonKey(defaultValue: '')
422+
final String decimalSeparator;
423+
424+
///The numeric grouping separator associated with the locale, e.g. "," or " ".
425+
@JsonKey(defaultValue: '')
426+
final String groupingSeparator;
427+
351428
///The currency symbol for the locale, e.g. $ for US locale.
352429
@JsonKey(defaultValue: '')
353430
final String currencySymbol;
@@ -356,19 +433,64 @@ class SKPriceLocaleWrapper {
356433
@JsonKey(defaultValue: '')
357434
final String currencyCode;
358435

436+
///The end quotation symbol associated with the locale, e.g. "”", "“", "»", or "」".
437+
@JsonKey(defaultValue: '')
438+
final String endDelimiterKey;
439+
440+
///The begin quotation symbol associated with the locale, e.g. "“", "„", "«", or "「".
441+
@JsonKey(defaultValue: '')
442+
final String beginDelimiterKey;
443+
444+
///The alternate end quotation symbol associated with the locale, e.g. "“", "„", "«", or "「".
445+
@JsonKey(defaultValue: '')
446+
final String alternateQuotationEndDelimiterKey;
447+
448+
///The alternating begin quotation symbol associated with the locale, e.g. "“", "„", "«", or "「".
449+
@JsonKey(defaultValue: '')
450+
final String alternateQuotationBeginDelimiterKey;
451+
359452
@override
360-
bool operator ==(Object other) {
361-
if (identical(other, this)) {
362-
return true;
363-
}
364-
if (other.runtimeType != runtimeType) {
365-
return false;
366-
}
367-
final SKPriceLocaleWrapper typedOther = other as SKPriceLocaleWrapper;
368-
return typedOther.currencySymbol == currencySymbol &&
369-
typedOther.currencyCode == currencyCode;
370-
}
453+
bool operator ==(Object other) =>
454+
identical(this, other) ||
455+
other is SKPriceLocaleWrapper &&
456+
runtimeType == other.runtimeType &&
457+
localeIdentifier == other.localeIdentifier &&
458+
countryCode == other.countryCode &&
459+
languageCode == other.languageCode &&
460+
scriptCode == other.scriptCode &&
461+
variantCode == other.variantCode &&
462+
collationIdentifier == other.collationIdentifier &&
463+
collatorIdentifier == other.collatorIdentifier &&
464+
usesMetricSystem == other.usesMetricSystem &&
465+
measurementSystem == other.measurementSystem &&
466+
decimalSeparator == other.decimalSeparator &&
467+
groupingSeparator == other.groupingSeparator &&
468+
currencySymbol == other.currencySymbol &&
469+
currencyCode == other.currencyCode &&
470+
endDelimiterKey == other.endDelimiterKey &&
471+
beginDelimiterKey == other.beginDelimiterKey &&
472+
alternateQuotationEndDelimiterKey ==
473+
other.alternateQuotationEndDelimiterKey &&
474+
alternateQuotationBeginDelimiterKey ==
475+
other.alternateQuotationBeginDelimiterKey;
371476

372477
@override
373-
int get hashCode => hashValues(this.currencySymbol, this.currencyCode);
478+
int get hashCode =>
479+
localeIdentifier.hashCode ^
480+
countryCode.hashCode ^
481+
languageCode.hashCode ^
482+
scriptCode.hashCode ^
483+
variantCode.hashCode ^
484+
collationIdentifier.hashCode ^
485+
collatorIdentifier.hashCode ^
486+
usesMetricSystem.hashCode ^
487+
measurementSystem.hashCode ^
488+
decimalSeparator.hashCode ^
489+
groupingSeparator.hashCode ^
490+
currencySymbol.hashCode ^
491+
currencyCode.hashCode ^
492+
endDelimiterKey.hashCode ^
493+
beginDelimiterKey.hashCode ^
494+
alternateQuotationEndDelimiterKey.hashCode ^
495+
alternateQuotationBeginDelimiterKey.hashCode;
374496
}

packages/in_app_purchase/in_app_purchase_ios/lib/src/store_kit_wrappers/sk_product_wrapper.g.dart

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/in_app_purchase/in_app_purchase_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: in_app_purchase_ios
22
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the iOS StoreKit Framework.
33
repository: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase_ios
4-
version: 0.1.0
4+
version: 0.1.1
55

66
flutter:
77
plugin:

packages/in_app_purchase/in_app_purchase_ios/test/store_kit_wrappers/sk_product_test.dart

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,27 @@ void main() {
4444
final SKProductDiscountWrapper wrapper =
4545
SKProductDiscountWrapper.fromJson(<String, dynamic>{});
4646
expect(wrapper.price, '');
47-
expect(wrapper.priceLocale,
48-
SKPriceLocaleWrapper(currencyCode: '', currencySymbol: ''));
47+
expect(
48+
wrapper.priceLocale,
49+
SKPriceLocaleWrapper(
50+
localeIdentifier: '',
51+
countryCode: '',
52+
languageCode: '',
53+
scriptCode: '',
54+
variantCode: '',
55+
collationIdentifier: '',
56+
collatorIdentifier: '',
57+
usesMetricSystem: true,
58+
measurementSystem: '',
59+
decimalSeparator: '',
60+
groupingSeparator: '',
61+
currencySymbol: '',
62+
currencyCode: '',
63+
endDelimiterKey: '',
64+
beginDelimiterKey: '',
65+
alternateQuotationEndDelimiterKey: '',
66+
alternateQuotationBeginDelimiterKey: '',
67+
));
4968
expect(wrapper.numberOfPeriods, 0);
5069
expect(wrapper.paymentMode, SKProductDiscountPaymentMode.payAsYouGo);
5170
expect(
@@ -69,8 +88,27 @@ void main() {
6988
expect(wrapper.productIdentifier, '');
7089
expect(wrapper.localizedTitle, '');
7190
expect(wrapper.localizedDescription, '');
72-
expect(wrapper.priceLocale,
73-
SKPriceLocaleWrapper(currencyCode: '', currencySymbol: ''));
91+
expect(
92+
wrapper.priceLocale,
93+
SKPriceLocaleWrapper(
94+
localeIdentifier: '',
95+
countryCode: '',
96+
languageCode: '',
97+
scriptCode: '',
98+
variantCode: '',
99+
collationIdentifier: '',
100+
collatorIdentifier: '',
101+
usesMetricSystem: true,
102+
measurementSystem: '',
103+
decimalSeparator: '',
104+
groupingSeparator: '',
105+
currencySymbol: '',
106+
currencyCode: '',
107+
endDelimiterKey: '',
108+
beginDelimiterKey: '',
109+
alternateQuotationEndDelimiterKey: '',
110+
alternateQuotationBeginDelimiterKey: '',
111+
));
74112
expect(wrapper.subscriptionGroupIdentifier, null);
75113
expect(wrapper.price, '');
76114
expect(wrapper.subscriptionPeriod, null);

0 commit comments

Comments
 (0)