【发布时间】:2022-03-06 23:22:13
【问题描述】:
我正在使用以下代码来获取枚举值和与之关联的相应字符串。我想知道是否有更简单的方法来实现这一点?
enum StyleType {
casual,
chic,
urban,
vintage,
punk,
}
class Style{
final StyleType type;
Style(this.type);
@override
String toString() {
switch (type) {
case StyleType.casual:
return 'Casual';
case StyleType.chic:
return 'Chic';
case StyleType.punk:
return 'Punk';
case StyleType.urban:
return 'Urban';
case StyleType.vintage:
return 'Vintage';
}
}
}
【问题讨论】: