From e69aab7a04c3fa57a689dc85f6b8074c99eb3bee Mon Sep 17 00:00:00 2001 From: SomnusVeritas Date: Tue, 17 Oct 2023 18:05:35 +0200 Subject: [PATCH] Added a getName function to convert enum names --- lib/models/difficulty.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/models/difficulty.dart b/lib/models/difficulty.dart index a9fcd1b..1edcd3f 100644 --- a/lib/models/difficulty.dart +++ b/lib/models/difficulty.dart @@ -1,8 +1,12 @@ class DifficultyUtil { - static List get difficulties { - return List.generate(Difficulty.values.length, - (index) => Difficulty.values.elementAt(index).name); + /// Converts lowerCamelCase or UpperCamelCase enum-names to 'normal' Strings + static String getName(Difficulty difficulty) { + 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 }