dart_mapper 0.1.0 copy "dart_mapper: ^0.1.0" to clipboard
dart_mapper: ^0.1.0 copied to clipboard

The dart mapper annotations.

dart_mapper #

A simple library to map Dart objects.

Getting started #

Add the following dependencies to your pubspec.yaml:

dependencies:
  dart_mapper: latest

dev_dependencies:
  build_runner: ^2.4.13
  dart_mapper_generator: latest

Create an abstract mapper class with the Mapper and Mapping annotation:


import 'package:dart_mapper/dart_mapper.dart';

part 'mixed.g.dart';

class MixedObject {
  final String name;
  final int age;
  final bool isAdult;
  final DateTime? birthday;

  MixedObject(
    this.name,
    this.age, {
      required this.isAdult,
      this.birthday,
    },
  );
}

class AnotherMixedObject {
  final String name;
  final int age;
  final bool adult;
  final DateTime? birthday;

  AnotherMixedObject(
    this.name,
    this.age, {
      required this.adult,
      this.birthday,
    },
  );
}

@Mapper()
abstract class MixedMapper {
  @Mapping(target: 'adult', source: 'isAdult')
  AnotherMixedObject toAnotherMixedObject(MixedObject mixedObject);

  @Mapping(target: 'isAdult', source: 'adult')
  MixedObject toMixedObject(AnotherMixedObject anotherMixedObject);
}

Run the following command to generate the barrel files:

dart run build_runner build --delete-conflicting-outputs
0
likes
0
points
882
downloads

Publisher

verified publishermylittlesuite.com

Weekly Downloads

The dart mapper annotations.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on dart_mapper