Last active
January 23, 2022 16:44
-
-
Save ElforL/c9a58402e44d71456e0e5576e6d14d07 to your computer and use it in GitHub Desktop.
An extension that adds `toShortString()` method to enums.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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