Closed cyberpwnn closed 3 years ago
It is not useful to use @Reflectable()
as an annotation on a class, that will just make it impossible to run the reflectable code generator.
The intended approach is that you have an immediate subclass of Reflectable
which is used to declare a specific level of reflection support, e.g.,
class Reflector extends Reflectable {
const Reflector()
: super(instanceInvokeCapability, newInstanceCapability,
declarationsCapability);
}
const reflector = Reflector();
and then you'd annotate the relevant classes using @reflector
, e.g.,
@reflector
class GuideAction {
...
}
If there is no constant like reflector
then you can also use @Reflector()
.
Said Reflector
class (and accompanying reflector
constant, if available) are used to specify a particular amount of reflection support. In the example above, you'll get support for invocation of instance members (because instanceInvokeCapability
is included), for invocation of constructors (because of newInstanceCapability
), and so on.
If the JSON package you are using is this one then I don't think there is any support for reflectable. So you'd need to write your own Reflector
class.
Check out the tests in order to see a bunch of examples; searching for extends Reflectable
will give you relevant hits. The test programs also show how to get access to the generated code (by having an import of a library whose name is of the form *.reflectable.dart
). To get an overview of the features, take a look at 'The Design of Reflectable Capabilities'.
@cyberpwnn, I'll close this issue. Please create new ones as needed if you encounter any issues.
@cyberpwnn, does it work now? ;-)
It's pretty simple, I'm trying to have a json_serializable object that i can query field names / update field names via an Instance mirror the main reason is because I have a subclasses with jsonserializable (different types which fit in a parent json object) but ignoring all of that, I'm not sure how to setup very basic reflection.
I'm testing the reflection in a random flutter widget when a button is tapped
However when running the build_runner
Im not using any reflection in lib/main.dart nor is it reflectable. Im not sure what i'm doing wrong here.