'Dynamicly call a variable from enum values
In my flutter app, I organize my strings with LocalizationsDelegate to manage locale language.
So to call a string, I write :
Languages.of(context).NAME_VARIABLE;
I have never seen what I'm trying to do and I'm not sure how to word it, so I'm gonna try to show what I want to achieve.
Let's say I have an enum class like this :
enum Numbers {
one,
two,
three,
}
I would like to dynamicly call strings (which I would have already added to my Languages files), something in this spirit :
List<String> numbersStr = <String>[];
for (String number in Numbers.values) {
numbersStr.add(Languages.of(context).number);
}
Is there any way to do something like that, or do I have to manually link each value to its string?
Solution 1:[1]
I haven't used it with translations but maybe its worth a try. https://pub.dev/packages/enhanced_enum
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Christian |
