Skip to content

Commit 342b455

Browse files
kevmooamantoux
authored andcommitted
[in_app_purchase] Update to the latest pkg:json_serializable (flutter#4434)
- Remove unneeded class now that enum helpers can be generated without one - Code reorganization - Remove superflous JsonKey values
1 parent f656c56 commit 342b455

28 files changed

+216
-443
lines changed

packages/in_app_purchase/in_app_purchase/build.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
## 0.1.6
2+
3+
* Require Dart SDK >= 2.14.
4+
* Update `json_annotation` dependency to `^4.3.0`.
5+
16
## 0.1.5+1
27

38
* Fix a broken link in the README.
9+
410
## 0.1.5
511

612
* Introduced the `SkuDetailsWrapper.introductoryPriceAmountMicros` field of the correct type (`int`) and deprecated the `SkuDetailsWrapper.introductoryPriceMicros` field.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# See https://pub.dev/packages/build_config
12
targets:
23
$default:
34
builders:
45
json_serializable:
56
options:
67
any_map: true
7-
create_to_json: true
8+
create_to_json: false

packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.dart

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'package:flutter/services.dart';
6+
77
import 'package:flutter/foundation.dart';
8+
import 'package:flutter/services.dart';
89
import 'package:json_annotation/json_annotation.dart';
10+
911
import '../../billing_client_wrappers.dart';
1012
import '../channel.dart';
1113
import 'purchase_wrapper.dart';
1214
import 'sku_details_wrapper.dart';
13-
import 'enum_converters.dart';
15+
16+
part 'billing_client_wrapper.g.dart';
1417

1518
/// Method identifier for the OnPurchaseUpdated method channel method.
1619
@visibleForTesting
@@ -364,6 +367,7 @@ typedef void OnBillingServiceDisconnected();
364367
/// [`BillingClient.BillingResponse`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.BillingResponse).
365368
/// See the `BillingResponse` docs for more explanation of the different
366369
/// constants.
370+
@JsonEnum(alwaysCreate: true)
367371
enum BillingResponse {
368372
// WARNING: Changes to this class need to be reflected in our generated code.
369373
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
@@ -418,11 +422,32 @@ enum BillingResponse {
418422
itemNotOwned,
419423
}
420424

425+
/// Serializer for [BillingResponse].
426+
///
427+
/// Use these in `@JsonSerializable()` classes by annotating them with
428+
/// `@BillingResponseConverter()`.
429+
class BillingResponseConverter implements JsonConverter<BillingResponse, int?> {
430+
/// Default const constructor.
431+
const BillingResponseConverter();
432+
433+
@override
434+
BillingResponse fromJson(int? json) {
435+
if (json == null) {
436+
return BillingResponse.error;
437+
}
438+
return $enumDecode(_$BillingResponseEnumMap, json);
439+
}
440+
441+
@override
442+
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object]!;
443+
}
444+
421445
/// Enum representing potential [SkuDetailsWrapper.type]s.
422446
///
423447
/// Wraps
424448
/// [`BillingClient.SkuType`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.SkuType)
425449
/// See the linked documentation for an explanation of the different constants.
450+
@JsonEnum(alwaysCreate: true)
426451
enum SkuType {
427452
// WARNING: Changes to this class need to be reflected in our generated code.
428453
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
@@ -437,13 +462,34 @@ enum SkuType {
437462
subs,
438463
}
439464

465+
/// Serializer for [SkuType].
466+
///
467+
/// Use these in `@JsonSerializable()` classes by annotating them with
468+
/// `@SkuTypeConverter()`.
469+
class SkuTypeConverter implements JsonConverter<SkuType, String?> {
470+
/// Default const constructor.
471+
const SkuTypeConverter();
472+
473+
@override
474+
SkuType fromJson(String? json) {
475+
if (json == null) {
476+
return SkuType.inapp;
477+
}
478+
return $enumDecode(_$SkuTypeEnumMap, json);
479+
}
480+
481+
@override
482+
String toJson(SkuType object) => _$SkuTypeEnumMap[object]!;
483+
}
484+
440485
/// Enum representing the proration mode.
441486
///
442487
/// When upgrading or downgrading a subscription, set this mode to provide details
443488
/// about the proration that will be applied when the subscription changes.
444489
///
445490
/// Wraps [`BillingFlowParams.ProrationMode`](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode)
446491
/// See the linked documentation for an explanation of the different constants.
492+
@JsonEnum(alwaysCreate: true)
447493
enum ProrationMode {
448494
// WARNING: Changes to this class need to be reflected in our generated code.
449495
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
@@ -477,7 +523,28 @@ enum ProrationMode {
477523
deferred,
478524
}
479525

526+
/// Serializer for [ProrationMode].
527+
///
528+
/// Use these in `@JsonSerializable()` classes by annotating them with
529+
/// `@ProrationModeConverter()`.
530+
class ProrationModeConverter implements JsonConverter<ProrationMode, int?> {
531+
/// Default const constructor.
532+
const ProrationModeConverter();
533+
534+
@override
535+
ProrationMode fromJson(int? json) {
536+
if (json == null) {
537+
return ProrationMode.unknownSubscriptionUpgradeDowngradePolicy;
538+
}
539+
return $enumDecode(_$ProrationModeEnumMap, json);
540+
}
541+
542+
@override
543+
int toJson(ProrationMode object) => _$ProrationModeEnumMap[object]!;
544+
}
545+
480546
/// Features/capabilities supported by [BillingClient.isFeatureSupported()](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.FeatureType).
547+
@JsonEnum(alwaysCreate: true)
481548
enum BillingClientFeature {
482549
// WARNING: Changes to this class need to be reflected in our generated code.
483550
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
@@ -504,3 +571,24 @@ enum BillingClientFeature {
504571
@JsonValue('subscriptionsUpdate')
505572
subscriptionsUpdate
506573
}
574+
575+
/// Serializer for [BillingClientFeature].
576+
///
577+
/// Use these in `@JsonSerializable()` classes by annotating them with
578+
/// `@BillingClientFeatureConverter()`.
579+
class BillingClientFeatureConverter
580+
implements JsonConverter<BillingClientFeature, String> {
581+
/// Default const constructor.
582+
const BillingClientFeatureConverter();
583+
584+
@override
585+
BillingClientFeature fromJson(String json) {
586+
return $enumDecode<BillingClientFeature, dynamic>(
587+
_$BillingClientFeatureEnumMap.cast<BillingClientFeature, dynamic>(),
588+
json);
589+
}
590+
591+
@override
592+
String toJson(BillingClientFeature object) =>
593+
_$BillingClientFeatureEnumMap[object]!;
594+
}

packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/billing_client_wrapper.g.dart

Lines changed: 43 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_android/lib/src/billing_client_wrappers/enum_converters.dart

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)