Easy Dart Enum
Made by Benjamin Mahmić ("https://github.com/BenjaminMahmic")
Extension link: "https://marketplace.visualstudio.com/items?itemName=BenjaminMahmic.easy-dart-enum"
- Select complete enum
- Call Quick Fix (Windows:
Ctrl + .
or Mac:⌘ + .
) and selectGenerate (is)Enum Extension
- That's it! 🎉
enum SubscriptionType {
free,
monthly,
annal,
}
extension SubscriptionTypeExtension on SubscriptionType {
bool get isFree => this == SubscriptionType.free;
bool get isMonthly => this == SubscriptionType.monthly;
bool get isAnnual => this == SubscriptionType.annual;
}
final subscriptionType = SubscriptionType.monthly;
void main() {
print(subscriptionType.isMonthly); // true
print(subscriptionType.isAnnual); // false
}
Enjoy! 🚀