enhanced_enum
0.2.4, released 4 years ago by famedly.com
Generator for enum extensions, string conversion, and pattern matching methods.
WASM-ready
What it does
Enhanced Enum generates utility methods for enums such as parsing from strings, mapping naming conventions like snake_case, and adding when/maybeWhen pattern matching capabilities. It uses build_runner to generate the extension code.
AI-written summary of version 0.2.4, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to parse enums from string representations easily.
- You want pattern matching methods like when() and maybeWhen() on enums.
- You need custom naming conventions like snake_case or screamingSnakeCase for enums.
Skip it when
- You want to avoid code generation and build_runner dependencies in your project.
Strengths
- Supports multiple naming conventions out of the box.
- Provides built-in pattern matching methods (when, maybeWhen).
- Allows custom overrides for individual enum values.
Weaknesses
- Requires build_runner and code generation setup.
- Depends on an extra generator package.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 0
Add enhanced_enum to dependencies and enhanced_enum_generator as a dev dependency, then run build_runner.
import 'package:enhanced_enum/enhanced_enum.dart';
part 'main.g.dart';
@EnhancedEnum()
enum Animals { fox, rabbit, redPanda }
void main() {
Animals.values.fromString('fox');
Animals.fox.when(fox: () => 1, rabbit: () => 2, redPanda: () => 3);
}Alternatives
Packages that do the same job and could replace enhanced_enum.
- freezed_annotation
Freezed also offers advanced union and enum-like code generation features.
78Compare