Skip to content

Commit 5a9abd5

Browse files
committed
model: Add ChannelPostPolicy.fromInt method
1 parent 32b301c commit 5a9abd5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/api/model/model.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ enum ChannelPostPolicy {
382382
final int? apiValue;
383383

384384
int? toJson() => apiValue;
385+
386+
/// Get a [ChannelPostPolicy] from a nullable int.
387+
///
388+
/// Example:
389+
/// 2 -> ChannelPostPolicy.administrators
390+
/// null -> ChannelPostPolicy.unknown
391+
static ChannelPostPolicy fromInt(int? value) => _byIntValue[value]!;
392+
393+
// _$…EnumMap is thanks to `alwaysCreate: true` and `fieldRename: FieldRename.kebab`
394+
static final _byIntValue = _$ChannelPostPolicyEnumMap
395+
.map((key, value) => MapEntry(value, key));
385396
}
386397

387398
/// As in `subscriptions` in the initial snapshot.

0 commit comments

Comments
 (0)