增强的枚举
A massive update has landed for enum to super-charge them. We use leverage extensions to extend the functionality of enums including defining methods. Starting from Dart 2.17, we no longer need to use our older model to work with enum .
enum Cars {
tesla('Model X', 200);
bmw('X6', 120);
porsche('Tycon', 220);
final String name;
final int price;
const Cars(this.name, this.price);
String get nameAndPrice => '$name:$price';
String greeting(String yourName) {
return 'My name is $yourName and I have a $name that costs $price!';