annotation_crawler 1.1.1

Annotation Crawler #

Helps finding annotated declarations in a particular scope.

The main functions to use in this library are:

// Returns a List of AnnotatedDeclaration for each top level declaration that has Foo as annotation.
// Does the same, but only for declarations in SomeClass
annotatedDeclarations(Foo, on: SomeClass);
// Returns a List of ClassMirror for each class that has Foo as annotation.
// Returns a List of MethodMirror for each method on SomeClass that has Foo as annotation.
findMethodsOnClass(SomeClass, Foo);
// Returns a List of MethodMirror for each method on someObject that has Foo as annotation.
findMethodsOnInstance(someObject, Foo);

1.1.1 #

  • Add implicit-casts: false and implicit-dynamics: false to analysis option to be strong mode safe

1.1.0 #

  • annotatedDeclarations now expects a Type as the on parameter: annotatedDeclarations(Foo, on: SomeClass);
  • Added a proper example to example/main.dart
  • Add CI tests for formatting and analysis

1.0.1 #

  • Fix README example

1.0.0 #

  • Started the changelog
  • Made this package dart 2.0 compatible


import 'dart:mirrors';

import 'package:annotation_crawler/annotation_crawler.dart';

class Author {
  final String name;
  const Author(;

class Scene {
  final int act;
  final int scene;
  const Scene({this.act, this.scene});

abstract class Play {
  final String name;


  void perform();

@Author('Arthur Miller')
class MajestyPlay extends Play {
  MajestyPlay() : super('Her majesty\'s Theater');

  perform() {

  @Scene(act: 1, scene: 1)
  void performAct1Scene1() => print('Performing play "$name" act 1 scene 1.');

  @Scene(act: 1, scene: 2)
  void performAct1Scene2() => print('Performing play "$name" act 1 scene 2.');

  @Scene(act: 2, scene: 1)
  void performAct2Scene1() => print('Performing play "$name" act 2 scene 1.');

void main() {
  // Perform all plays written by Arthur Miller.
      .where((decl) =>
          decl.declaration is ClassMirror &&
          decl.annotation == const Author("Arthur Miller"))
      .forEach((decl) {
    final ClassMirror playClass = decl.declaration;
    final Play play =
        playClass.newInstance(const Symbol(''), <dynamic>[]).reflectee;

  print('Now playing only act 2 scene 1:');

  final majestyPlay = new MajestyPlay();

  final declaration = annotatedDeclarations(Scene, on: majestyPlay.runtimeType)
      .singleWhere((decl) {
    final Scene scene = decl.annotation;
    return scene.act == 2 && scene.scene == 1;

  /// Invoke the found method on given object.
  reflect(majestyPlay).invoke(declaration.declaration.simpleName, <dynamic>[]);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  annotation_crawler: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:annotation_crawler/annotation_crawler.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/annotation_crawler.dart. (-3.93 points)

Analysis of lib/annotation_crawler.dart reported 8 hints, including:

line 59 col 29: Use = to separate a named parameter from its default value.

line 61 col 10: Unnecessary new keyword.

line 69 col 51: Unnecessary new keyword.

line 76 col 5: Unnecessary new keyword.

line 87 col 20: Use = to separate a named parameter from its default value.

Maintenance suggestions

Package is getting outdated. (-56.99 points)

The package was last published 81 weeks ago.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >1.5.0 <3.0.0
Dev dependencies
test any