Answer
Overview
Dart enum members can technically be named in any case, but there are clear conventions based on Dart's style guide.
Dart Style Guide — Enum Convention
Starting from Dart 2.17+, enum members should use (not textlowerCamelCase
text
UPPER_CASEdart// ✅ CORRECT — Modern Dart style (lowerCamelCase) enum Status { pending, inProgress, completed, failed, } enum Direction { north, south, east, west, } // ❌ OLD style (avoid in modern Dart) enum OldStyle { PENDING, // Avoid — this is C/Java style IN_PROGRESS, COMPLETED, }
Enhanced Enums (Dart 2.17+)
dartenum Priority { low(1, 'Low Priority', Colors.green), medium(2, 'Medium Priority', Colors.orange), high(3, 'High Priority', Colors.red), critical(4, 'Critical!', Colors.purple); const Priority(this.level, this.label, this.color); final int level; final String label; final Color color; bool get isUrgent => level >= 3; static Priority fromLevel(int level) => values.firstWhere((e) => e.level == level); } // Usage final current = Priority.high; print(current.label); // High Priority print(current.isUrgent); // true print(current.color); // Colors.red
Enum with switch (Dart 3 exhaustive)
dartenum AppTheme { light, dark, system } String getThemeLabel(AppTheme theme) { return switch (theme) { AppTheme.light => 'Light Mode', AppTheme.dark => 'Dark Mode', AppTheme.system => 'System Default', }; }
Common Enum Properties
dartenum Fruit { apple, banana, cherry } void main() { print(Fruit.apple.name); // 'apple' (String) print(Fruit.apple.index); // 0 print(Fruit.values); // [Fruit.apple, Fruit.banana, Fruit.cherry] // Parse from string final f = Fruit.values.byName('banana'); // Fruit.banana }
Convention Summary
| Style | Example | Recommendation |
|---|---|---|
| lowerCamelCase | text text | ✅ Dart standard |
| UPPER_CASE | text text | ❌ Old — avoid |
| PascalCase | text text | ❌ Not conventional |
Answer: Use
for enum members in Dart (e.g.,textlowerCamelCase, nottextStatus.inProgress). This follows the official Dart style guide.textStatus.IN_PROGRESS