generic_enum_builder 0.0.3 generic_enum_builder: ^0.0.3 copied to clipboard
Source code generator processing annotated generic_enum classes. It builds a value-instance map and json-serialization functions.
Generic Enum Builder #
Introduction #
GenericEnumBuilder
contains source code generating classes
based on source_gen and analyzer.
The provided builder can be configured to build generic enumeration classes
supporting json-serialization.
Generic enumeration classes appear to the user like a Dart enum
would.
For example, generic enums can be used in switch
statements, as annotations,
to initialize variables, or as default parameters in functions and constructors.
Configuration #
To use this library the following configuration steps are required:
- Include
generic_enum, generic_enum_annotation
as dependency in your pubspec.yaml file. Includegeneric_enum_builder, source_gen, build_runner
as dev_dependencies. - Create a class extending
GenericEnum
. See generic_enum#boilerplate. - Annotate the class with
@GenerateBuiltMap
and@GenerateJsonToFrom
. - Configure the build targets. Amend the generate_for entry to point to the
folder containing your generic enum classes.
In your local
build.yaml
file add the following builders:targets: $default: builders: # Configure the builder `pkg_name|builder_name` generic_enum_builder|map_builder: # Only run this builder on the specified input. enabled: true generate_for: - lib/*.dart # Configure the builder `pkg_name|builder_name` generic_enum_builder|json_builder: # Only run this builder on the specified input. enabled: true generate_for: - lib/*.dart
Building #
If you are using Flutter, build the project by running the command:
$ flutter packages pub run build_runner build --delete-conflicting-outputs
If you are using the Dart SDK use:
$ pub run build_runner build --delete-conflicting-outputs
Examples #
The package generic_enum_example provides a complete example on how to define and build
generic enumeration classes. As a starting point users could clone this repository, add
their own generic enum classes to the folder lib
and build the library.
Features and bugs #
Please file feature requests and bugs at the issue tracker.