feat(code_push_protocol): add hasActiveSubscription to User (#246)

This commit is contained in:
Felix Angelov
2023-04-06 14:13:37 -05:00
committed by GitHub
parent b92edcca99
commit 1dba7059fe
2 changed files with 8 additions and 1 deletions
@@ -8,7 +8,7 @@ part 'user.g.dart';
@JsonSerializable()
class User {
/// {@macro user}
const User({required this.id});
const User({required this.id, this.hasActiveSubscription = false});
/// Converts a Map<String, dynamic> to a [User]
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
@@ -18,4 +18,7 @@ class User {
/// The unique user identifier.
final int id;
/// Whether the user is currently a paying customer.
final bool hasActiveSubscription;
}
@@ -14,11 +14,15 @@ User _$UserFromJson(Map<String, dynamic> json) => $checkedCreate(
($checkedConvert) {
final val = User(
id: $checkedConvert('id', (v) => v as int),
hasActiveSubscription: $checkedConvert(
'has_active_subscription', (v) => v as bool? ?? false),
);
return val;
},
fieldKeyMap: const {'hasActiveSubscription': 'has_active_subscription'},
);
Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
'id': instance.id,
'has_active_subscription': instance.hasActiveSubscription,
};