functional_enum 1.1.6 copy "functional_enum: ^1.1.6" to clipboard
functional_enum: ^1.1.6 copied to clipboard

Code generator for functional enum that makes the use of enums much better.

example/lib/main.dart

import 'package:functional_enum_annotation/functional_enum_annotation.dart';

part 'main.g.dart';

@functionalEnum
enum Shape { square, circle, triangle }

void main() {
  final shape = Shape.circle;

  // all cases must be handled
  final message = shape.when(
    square: () => 'I am a Square',
    circle: () => 'I am a Circle',
    triangle: () => 'I am a Triangle',
  );
  print(message); // I am a Circle

  // all cases may not be handled but `orElse` cannot be null
  final canBeRotated = shape.maybeWhen(
    circle: () => false,
    orElse: () => true,
  );
  print(canBeRotated); // false

  // equivalent to print(shape == Shape.circle)
  print(shape.isCircle); // true
  print(shape.isSquare); // false
  print(shape.isTriangle); // false
}
14
likes
130
pub points
35%
popularity

Publisher

unverified uploader

Code generator for functional enum that makes the use of enums much better.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, build_config, functional_enum_annotation, source_gen

More

Packages that depend on functional_enum