Generate files from Dart code annotations and Mustache templates
- Generate files from Dart code annotations and Mustache templates
Install dependencies:
dev_dependencies:
build_runner:
mustache_generator:
git:
url: https://github.com/juancastillo0/template_generatorCreate a Mustache template within the lib directory (lib/templates/fieldsEnum.mustache):
enum {{name}}Fields {
{{# fields }}
{{ name }},
{{/ fields }}
}Create and annotate your model:
@FieldsEnumTemplate()
class Model {
final String fieldName;
const Model({
required this.fieldName,
});
}Run the code generator:
dart pub run build_runner watch --delete-conflicting-outputsThis will generate the following file:
enum ModelFields {
fieldName,
}You can check out the /example folder for a complete example.
TODO: Tell users more about the package: where to find more information, how to contribute to the package, how to file issues, what response they can expect from the package authors, and more.