Dart Enum de String
Fruit f = Fruit.values.firstWhere((e) => e.toString() == 'Fruit.' + str);
Hemang Joshi
Fruit f = Fruit.values.firstWhere((e) => e.toString() == 'Fruit.' + str);
enum Topic { none, computing, general }
extension TopicString on String {
Topic get topic {
switch (this) {
case 'computing':
return Topic.computing;
case 'general':
return Topic.general;
case 'none':
return Topic.none;
}
}
}
extension TopicExtension on Topic {
String get string {
switch (this) {
case Topic.computing:
return 'computing';
case Topic.general:
return 'general';
case Topic.none:
return 'none';
}
}
}