Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[in_app_purchase] Update to the latest pkg:json_serializable #4434

Merged
merged 7 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/in_app_purchase/in_app_purchase/build.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 0.1.6

* Require Dart SDK >= 2.14.
kevmoo marked this conversation as resolved.
Show resolved Hide resolved
* Update `json_annotation` dependency to `^4.3.0`.

## 0.1.5+1

* Fix a broken link in the README.

## 0.1.5

* Introduced the `SkuDetailsWrapper.introductoryPriceAmountMicros` field of the correct type (`int`) and deprecated the `SkuDetailsWrapper.introductoryPriceMicros` field.
Expand Down
3 changes: 2 additions & 1 deletion packages/in_app_purchase/in_app_purchase_android/build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# See https://pub.dev/packages/build_config
targets:
$default:
builders:
json_serializable:
options:
any_map: true
create_to_json: true
create_to_json: false
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
// found in the LICENSE file.

import 'dart:async';
import 'package:flutter/services.dart';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:json_annotation/json_annotation.dart';

import '../../billing_client_wrappers.dart';
import '../channel.dart';
import 'purchase_wrapper.dart';
import 'sku_details_wrapper.dart';
import 'enum_converters.dart';

part 'billing_client_wrapper.g.dart';

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

/// Serializer for [BillingResponse].
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@BillingResponseConverter()`.
class BillingResponseConverter implements JsonConverter<BillingResponse, int?> {
/// Default const constructor.
const BillingResponseConverter();

@override
BillingResponse fromJson(int? json) {
if (json == null) {
return BillingResponse.error;
}
return $enumDecode(_$BillingResponseEnumMap, json);
}

@override
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object]!;
}

/// Enum representing potential [SkuDetailsWrapper.type]s.
///
/// Wraps
/// [`BillingClient.SkuType`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.SkuType)
/// See the linked documentation for an explanation of the different constants.
@JsonEnum(alwaysCreate: true)
enum SkuType {
// WARNING: Changes to this class need to be reflected in our generated code.
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
Expand All @@ -437,13 +462,34 @@ enum SkuType {
subs,
}

/// Serializer for [SkuType].
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@SkuTypeConverter()`.
class SkuTypeConverter implements JsonConverter<SkuType, String?> {
/// Default const constructor.
const SkuTypeConverter();

@override
SkuType fromJson(String? json) {
if (json == null) {
return SkuType.inapp;
}
return $enumDecode(_$SkuTypeEnumMap, json);
}

@override
String toJson(SkuType object) => _$SkuTypeEnumMap[object]!;
}

/// Enum representing the proration mode.
///
/// When upgrading or downgrading a subscription, set this mode to provide details
/// about the proration that will be applied when the subscription changes.
///
/// Wraps [`BillingFlowParams.ProrationMode`](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode)
/// See the linked documentation for an explanation of the different constants.
@JsonEnum(alwaysCreate: true)
enum ProrationMode {
// WARNING: Changes to this class need to be reflected in our generated code.
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
Expand Down Expand Up @@ -477,7 +523,28 @@ enum ProrationMode {
deferred,
}

/// Serializer for [ProrationMode].
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@ProrationModeConverter()`.
class ProrationModeConverter implements JsonConverter<ProrationMode, int?> {
/// Default const constructor.
const ProrationModeConverter();

@override
ProrationMode fromJson(int? json) {
if (json == null) {
return ProrationMode.unknownSubscriptionUpgradeDowngradePolicy;
}
return $enumDecode(_$ProrationModeEnumMap, json);
}

@override
int toJson(ProrationMode object) => _$ProrationModeEnumMap[object]!;
}

/// Features/capabilities supported by [BillingClient.isFeatureSupported()](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.FeatureType).
@JsonEnum(alwaysCreate: true)
enum BillingClientFeature {
// WARNING: Changes to this class need to be reflected in our generated code.
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
Expand All @@ -504,3 +571,24 @@ enum BillingClientFeature {
@JsonValue('subscriptionsUpdate')
subscriptionsUpdate
}

/// Serializer for [BillingClientFeature].
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@BillingClientFeatureConverter()`.
class BillingClientFeatureConverter
implements JsonConverter<BillingClientFeature, String> {
/// Default const constructor.
const BillingClientFeatureConverter();

@override
BillingClientFeature fromJson(String json) {
return $enumDecode<BillingClientFeature, dynamic>(
_$BillingClientFeatureEnumMap.cast<BillingClientFeature, dynamic>(),
json);
}

@override
String toJson(BillingClientFeature object) =>
_$BillingClientFeatureEnumMap[object]!;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading