Skip to content

Instantly share code, notes, and snippets.

@ElforL
Last active January 23, 2022 16:44
Show Gist options
  • Save ElforL/c9a58402e44d71456e0e5576e6d14d07 to your computer and use it in GitHub Desktop.
Save ElforL/c9a58402e44d71456e0e5576e6d14d07 to your computer and use it in GitHub Desktop.
An extension that adds `toShortString()` method to enums.
/// Adds `toShortString()` method to [Enum].
extension EnumToShortString on Enum {
/// Returns the string of the **value**.
///
/// For example,
/// ```dart
/// var enum1 = MyEnum.val1;
/// print(enum1.toString()); /// 'MyEnum.val1'
/// print(enum1.toShortString()); /// 'val1'
/// ```
String toShortString() {
return toString().split('.').last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment