Added a getName function to convert enum names
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
class DifficultyUtil {
|
class DifficultyUtil {
|
||||||
static List<String> get difficulties {
|
/// Converts lowerCamelCase or UpperCamelCase enum-names to 'normal' Strings
|
||||||
return List<String>.generate(Difficulty.values.length,
|
static String getName(Difficulty difficulty) {
|
||||||
(index) => Difficulty.values.elementAt(index).name);
|
String name = difficulty.name
|
||||||
|
.replaceAllMapped(RegExp(r'[A-Z]'), (match) => ' ${match[0]}');
|
||||||
|
name = name[0].toUpperCase() + name.substring(1);
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only use camelCase or UpperCamelCase for names
|
||||||
enum Difficulty { veryEasy, easy, intermediate, hard, veryHard }
|
enum Difficulty { veryEasy, easy, intermediate, hard, veryHard }
|
||||||
|
|||||||
Reference in New Issue
Block a user