jeudi 28 février 2019

How to use dart Reflectable with classes in more files?

In documentation is example which is in one file and initialized from main() function. How to use this package in real world?

What I need is example how to use it in this simple project:

git@github.com:fidlip/reftest.git

lib/reflector.dart:

import 'package:reflectable/reflectable.dart';

class Reflector extends Reflectable {
  const Reflector() : super(invokingCapability);
}

const reflector = const Reflector();

lib/model_a.dart:

import 'package:untitled/reflector.dart';

@reflector
class ModelA {
  String prop;
}
void main() {}

lib/model_b.dart:

import 'package:untitled/reflector.dart';

@reflector
class ModelB {
  String prop;
}


void main() {}

bin/main.dart

import 'package:untitled/reflector.dart';

import '../lib/class_a.reflectable.dart' as a;
import '../lib/class_b.reflectable.dart' as b;


main(List<String> arguments) {
  a.initializeReflectable();
  b.initializeReflectable();

  reflector.annotatedClasses.forEach((cls) {
    print("Annotated class ${cls.qualifiedName}");
  });

}

pubspec.yaml

name: reftest
description: A sample command-line application.

environment:
  sdk: '>=2.1.0 <3.0.0'

dependencies:
  reflectable: ^2.0.10

dev_dependencies:
  pedantic: ^1.0.0
  test: ^1.0.0
  build_runner: any

build.yaml

targets:
  $default:
    builders:
      reflectable:
        generate_for:
          include:
            - lib/**.dart

Build this project: pub run build_runner build lib

when I run this project: pub run main.dart I got Annotated class .B but expected both classes (A and B) to be printed.

If you have an idea, pull requests are welcome





Aucun commentaire:

Enregistrer un commentaire