Skip to content

Commit 5f7cccd

Browse files
PIG208gnprice
authored andcommitted
api [nfc]: Add PropagateMode.fromRawString
Signed-off-by: Zixuan James Li <[email protected]>
1 parent b030737 commit 5f7cccd

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
@@ -954,4 +954,15 @@ enum PropagateMode {
954954
changeAll;
955955

956956
String toJson() => _$PropagateModeEnumMap[this]!;
957+
958+
/// Get a [PropagateMode] from a raw string. Throws if the string is
959+
/// unrecognized.
960+
///
961+
/// Example:
962+
/// 'change_one' -> PropagateMode.changeOne
963+
static PropagateMode fromRawString(String raw) => _byRawString[raw]!;
964+
965+
// _$…EnumMap is thanks to `alwaysCreate: true` and `fieldRename: FieldRename.snake`
966+
static final _byRawString = _$PropagateModeEnumMap
967+
.map((key, value) => MapEntry(value, key));
957968
}

0 commit comments

Comments
 (0)