Skip to content

Commit 4eed88c

Browse files
committed
model: Add ChannelPostPolicy.fromInt method
1 parent 73fc7e9 commit 4eed88c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/api/model/model.dart

+11
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,17 @@ enum ChannelPostPolicy {
378378
final int? apiValue;
379379

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

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

0 commit comments

Comments
 (0)