dart_mem_annotation 0.0.2 copy "dart_mem_annotation: ^0.0.2" to clipboard
dart_mem_annotation: ^0.0.2 copied to clipboard

A Code Generator Plugin to Generate Models, Entities and Mappers base on Annotation.

Dart Model Entity Mapper (MEM) Annotation

PubVersion PubPoints build Latest dartdocs

Pub

android ios ios linux windows mac-os

Mem Annotation Generator is a Code Generator Plugin to Generate Models, Entities and Mapper base on Annotation. This package designed to prevent adding extra codes to add Models, Entities and Mappers one by one. You can use it for Models, APIs and JSONs.

Contents: #

Getting Started #

Add dependencies in the pubspec.yaml:

dependencies:
  dart_mem_annotation: ^latest
  
  # If Freezed Code Generations needed:
  freezed: ^2.5.7
  json_annotation: ^4.9.0

dev_dependencies:
  build_runner: ^latest
  dart_mem_annotation_generator: ^latest

  # If Freezed Code Generations needed:
  freezed_annotation: ^2.4.4
  json_serializable: ^6.8.0

Generator Library Link on pub.dev:

Pub

Get the Changes by:

flutter pub get

or

dart pub get

Usage #

Import Annotation:

import 'package:dart_mem_annotation/annotation.dart';

Part Directives should also be provided for Generated Codes on top of dart file:

part '*filename*.mem.dart';

Add desired @Annotation on top of the desired class and set the desired Options. Also InnerClasses are supported.

Such as:

part 'some_file.mem.dart';

@Mem.all()
class SomeClass {
  SampleEnum? sampleEnum;
  String? name;
  String? description;
  InnerSample? innerClass;
  List<String>? sampleList;
  List<InnerSample>? innerSampleList;
}

@Mem.all(withFreezed: true)
class SomeInnerClass {
  const InnerSample({this.name, this.description});
  final String? name;
  final String? description;
}

Important

Important for Freezed Class:

InnerClasses if decorated with the annotation they all will have generated Model, Entity and Mappers, but if not, the class itself will use in the main class.

then you should run the build_runner to generate the codes and creating related file and include all the pages, controllers, components and repositories in one place and prepared to use. You can use

dart pub run build_runner build --delete-conflicting-outputs

All files will generate with *.mem.dart format.

You can check the /example for a more complete example, more details and further information. #

Options #

You can set some annotations and its Options in the @Annotation Available Annotations:

  • @Mem.all: Will Generate all options, including Mode, Entity, and Mappers.
  • Other Options are under Develop ...

Available Options:

  • @Mem
    • as: Change the Name of the Page in the dependencies and use it as another name.
    • withFreezed: All Generated Classes will decorate with @freezed Annotation, and all Freezed classes will generate after Mem Code Generation.
    • extendsBaseClass: (Not Recommended) - Generated Classes will extends the Original Annotated Class, and without this option all classes will be independent.

Note

All Classes with Freezed Annotation (if your mark withFreezed as true) should be provided by its own parts.

part '*filename*.mem.dart'; // For Meme Generator
part '*filename*.freezed.dart'; // For Freezed
part '*filename*.g.dart'; // For JsonSerializable with Freezed

Docs #

build

About Author #

Resam Taghipour #

Pub account Pub Pub

Packages and Dependencies #

Pub Pub Pub Pub

License #

This project is licensed under the 'BSD-3-Clause' License - see the LICENSE for details.

Pub

2
likes
0
points
248
downloads

Publisher

verified publisherresam.site

Weekly Downloads

A Code Generator Plugin to Generate Models, Entities and Mappers base on Annotation.

Homepage
Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

resam.site

License

unknown (license)

Dependencies

build_runner, dartdoc

More

Packages that depend on dart_mem_annotation