Skip to content

Instantly share code, notes, and snippets.

@Vanethos
Created October 27, 2020 12:08
Show Gist options
  • Save Vanethos/61ce1c1f665f7db5806ded167cd2e57a to your computer and use it in GitHub Desktop.
Save Vanethos/61ce1c1f665f7db5806ded167cd2e57a to your computer and use it in GitHub Desktop.
Enum extension
enum StarterPokemonEnum { bulbasaur, charmander, squirtle, }
/// This extension will give us the possibility to return a String
/// when we call the [name] getter
extension StarterPokemonToString on StarterPokemonEnum {
String get name {
switch (this) {
case StarterPokemonEnum.bulbasaur:
return "Bulbasaur";
case StarterPokemonEnum.charmander:
return "Charmander";
case StarterPokemonEnum.squirtle:
return "Squirtle";
default:
return "Missigno";
}
}
}
void main() {
/// Convert the list of all the values of the enum to a list of Strings
var startersList =
StarterPokemonEnum
/// Get all possible values for the enum
.values
/// Map them to their names
.map((pokemon) => pokemon.name)
.toList();
/// Print the List
print(startersList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment