better_enum 1.0.0 copy "better_enum: ^1.0.0" to clipboard
better_enum: ^1.0.0 copied to clipboard

Package that provides a better way (java-like) to write enums

example/main.dart

import 'package:better_enum/better_enum.dart';

class Meter extends Enum<int> {
  // Internal constructor to prevent other code to create new 
  // instances of our enum.
  // Name is optional, and the base-class also has functionality
  // to work without a name.
  const Meter._internal(int val, {String name}): super(val, name);

  // example how to create a named Enum instance. The name is used
  // only for the toString() method.
  static const Meter HIGH = const Meter._internal(100, name: "HIGH");
  static const Meter MIDDLE = const Meter._internal(50);
  static const Meter LOW = const Meter._internal(10);
}

main() {
    print(Meter.HIGH.toString());
    print(Meter.MIDDLE.toString());
    print(Meter.LOW.toString());
}
3
likes
40
pub points
0%
popularity

Publisher

verified publisherbithero.by

Package that provides a better way (java-like) to write enums

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

More

Packages that depend on better_enum