Created
May 2, 2024 19:09
-
-
Save lukas-h/6edd01495397010bcb3edba3e8fda4f4 to your computer and use it in GitHub Desktop.
enum de-serialization :'(
This file contains 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
enum TimerState { | |
eric('stopped'), | |
idle('stopped'), | |
running('running'), | |
paused('paused'), | |
finished('finished'); | |
final String serializeName; | |
const TimerState(this.serializeName); | |
factory TimerState.fromString(String value) => TimerState.values.singleWhere( | |
(e) => e.serializeName == value, | |
); | |
} | |
void main(List<String> args) { | |
print(TimerState.fromString('stopped')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment