dart_class_mapper 1.2.1 copy "dart_class_mapper: ^1.2.1" to clipboard
dart_class_mapper: ^1.2.1 copied to clipboard

Lightweight library for mapping classes in Dart. Ideal for converting between entities and DTOs objects with a simple and reusable API.

Dart Class Mapper #

A lightweight and simple package for class mapping in Dart, allowing flexible and reusable conversion between instance types.

🎯 Recursos #

  • ⚑ Simple and easy to use
  • πŸ” Avoids unnecessary code repetition
  • πŸ”„ Enables reuse of mappings
  • πŸ› οΈ Intuitive API with CreateMap and GetMapper

πŸ“¦ Installation #

Add Dart Class Mapper to your project via pubspec.yaml:

dependencies:
  dart_class_mapper: ^1.2.1

πŸš€ How to Use #

πŸ—οΈ Creating the Classes #

class User {
  String name;
  String email;
  String password;

  User({required this.name, required this.email, required this.password});
}

class UserGetDto {
  String name;
  String email;

  UserGetDto({required this.name, required this.email});
}

πŸ”— Creating the Mapping #

Use CreateMap to register mappings between classes.

CreateMap<UserGetDto, User>((user) => UserGetDto(
        name: user.name,
        email: user.email,
      ));

πŸ” Retrieving the Mapping #

Use GetMapper to retrieve mappings.

final userGetDto = GetMapper<UserGetDto, User>().value(user);

Usage Example #

void main() {
  CreateMap<UserGetDto, User>((user) => UserGetDto(
        name: user.name,
        email: user.email,
      ));

  final user = User(
    name: 'John Doe',
    email: 'john.doe@example',
    password: 'teste',
  );

  final userGetDto = GetMapper<UserGetDto, User>().value(user);

  print(userGetDto.name); // John Doe
  print(userGetDto.email); // john.doe@example
}

For more usage examples: #

1
likes
155
points
47
downloads

Publisher

verified publisherlucasmateusdev.com.br

Weekly Downloads

Lightweight library for mapping classes in Dart. Ideal for converting between entities and DTOs objects with a simple and reusable API.

Repository (GitHub)
View/report issues

Topics

#class-mapper #mappings #automapper #object-transform #mapper

Documentation

API reference

License

MIT (license)

More

Packages that depend on dart_class_mapper