enum_class_generator 0.2.0

  • README.md
  • Installing
  • Versions
  • --

Enum Classes for Dart #

Introduction #

Enum Classes provide classes with enum features and are part of Libraries for Object Oriented Dart.

Motivation #

Enums are very helpful in modelling the real world: whenever there are a small fixed set of options, an enum is a natural choice. For an object oriented design, though, enums need to be classes. Dart falls short here, so Enum Classes provide what's missing!

Design #

  • Constants have name and toString, can be used in switch statements, and are real classes that can hold code and implement interfaces
  • Generated values method that returns all the enum values in a BuiltSet (immutable set)
  • Generated valueOf method that takes a String

Using Enum Classes #

Enum Classes use the source_gen library for code generation. The typical way to use it is via a build.dart tool that you create for your project. When you run it, all the generated files are updated.

Here's what you need to do to use Enum Classes:

  1. Add a library dependency on enum_class to your pubspec.yaml
  2. Add a dev dependency on enum_class_generator to your pubspec.yaml
  3. Create a build.dart for your project. See example, below.
  4. Run pub run tools/build.dart whenever you need to update the generated files.
  5. To make an Enum Class, import package:enum_class/enum_class.dart then extend EnumClass.

See this example for a full project with a build.dart and an enum.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  enum_class_generator: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:enum_class_generator/enum_class_generator.dart';
  
Version Uploaded Documentation Archive
2.0.0 Nov 22, 2016 Go to the documentation of enum_class_generator 2.0.0 Download enum_class_generator 2.0.0 archive
1.1.2 Nov 14, 2016 Go to the documentation of enum_class_generator 1.1.2 Download enum_class_generator 1.1.2 archive
1.1.1 Oct 19, 2016 Go to the documentation of enum_class_generator 1.1.1 Download enum_class_generator 1.1.1 archive
1.1.0 Sep 21, 2016 Go to the documentation of enum_class_generator 1.1.0 Download enum_class_generator 1.1.0 archive
1.0.0 Jul 11, 2016 Go to the documentation of enum_class_generator 1.0.0 Download enum_class_generator 1.0.0 archive
0.2.2 Jun 7, 2016 Go to the documentation of enum_class_generator 0.2.2 Download enum_class_generator 0.2.2 archive
0.2.1 Jun 6, 2016 Go to the documentation of enum_class_generator 0.2.1 Download enum_class_generator 0.2.1 archive
0.2.0 May 30, 2016 Go to the documentation of enum_class_generator 0.2.0 Download enum_class_generator 0.2.0 archive
0.1.0 May 25, 2016 Go to the documentation of enum_class_generator 0.1.0 Download enum_class_generator 0.1.0 archive
0.0.6 Oct 23, 2015 Go to the documentation of enum_class_generator 0.0.6 Download enum_class_generator 0.0.6 archive

All 15 versions...

Awaiting analysis to complete.