Skip to content
pubscout

reflection_factory

2.13.0, released 5 weeks ago by an unverified publisher

Allows Dart reflection and method proxies using code generation across all platforms.

WASM-ready
$ flutter pub add reflection_factory
Source repository

What it does

Enables reflection capabilities for local and third-party classes through code generation and bridge annotations. It also supports class proxies to intercept method calls and tools for JSON decoding into entities.

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

Use it when

  • You need reflection features in Dart where native dart:mirrors is not supported.
  • You need to reflect on third-party classes using bridge annotations.
  • You want to create class proxies that intercept method calls.

Skip it when

  • You want to avoid code generation steps during development.
  • You do not need runtime reflection or dynamic method invocation.

Strengths

  • Works across all Dart platforms where native mirrors are unavailable.
  • Supports third-party classes through reflection bridges.
  • Provides class proxies for intercepting method calls.

Weaknesses

  • Requires maintaining a build_runner code generation step.
  • Requires proper part directives in files where reflection is enabled.

Setup

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

Add reflection_factory to dependencies and build_runner to dev_dependencies, then run dart run build_runner build.

import 'package:reflection_factory/reflection_factory.dart';

part 'some_source_file.reflection.g.dart';

@EnableReflection()
class User {
  String? email;
  User(this.email);
}

void main() {
  var user = User('joe@mail.com');
  var userReflection = user.reflection;
  print('email: ${userReflection.field('email')?.get()}');
}

Alternatives

Packages that do the same job and could replace reflection_factory.

  • freezed

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

  • copy_with_extension_gen

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

  • json_annotation

    Provides annotations for json_serializable to generate JSON (de)serialization code.

  • source_gen

    Source code generation builders and utilities for the Dart build system.

Works with

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