Skip to content
pubscout

auto_mappr

2.18.0, released 4 weeks ago by netglade.cz

Code generation package for mapping between different objects with ease.

$ flutter pub add auto_mappr
Source repository

What it does

AutoMappr generates object-to-object mapping code at pre-compile time, eliminating manual mapping boilerplate. It analyzes source and target classes to automatically map matching fields, and supports complex configurations like field renaming, custom mapping functions, ignored fields, default values, and iterable/map conversions.

AI-written summary of version 2.18.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You frequently map objects between layers (e.g., DTOs to domain models and domain models to UI models).
  • You want pre-compile time safety and speed without writing tedious mapping boilerplate by hand.

Skip it when

  • You prefer runtime reflection-based mapping without build steps.
  • Your project does not use code generation or build_runner.

Strengths

  • Moves mapping overhead from runtime to pre-compile time for fast execution.
  • Extensive customization options including custom mapping functions, field ignores, defaults, and reverse mapping.
  • Works well with packages like equatable and json_serializable.

Weaknesses

  • Requires running a build_runner step whenever mappings or models change.
  • Strict type inference must be handled carefully using explicit types or generics.

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
10

Add auto_mappr, auto_mappr_annotation, and build_runner as dependencies, then run dart run build_runner build.

import 'package:auto_mappr_annotation/auto_mappr_annotation.dart';

import 'my_file.auto_mappr.dart';

@AutoMappr([
  MapType<UserDto, User>(),
])
class Mappr extends $Mappr {}

void main() {
  final mappr = Mappr();
  User user = mappr.convert(UserDto(...));
}

Alternatives

Packages that do the same job and could replace auto_mappr.

  • freezed

    Code generation for immutable classes, tagged unions, and cloning without boilerplate.

  • pigeon

    Type-safe code generator for communication between Flutter and host platforms.

  • copy_with_extension

    Annotation for generating copyWith extensions code using copy_with_extension_gen.

  • copy_with_extension_gen

    Generate type‑safe copyWith extensions for annotated classes and record typedefs.

Works with

Packages commonly used together with auto_mappr: ones it builds on, ones built on it, and its own family.