google / reflectable.dart

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.
https://pub.dev/packages/reflectable
BSD 3-Clause "New" or "Revised" License
374 stars 56 forks source link

How to reflect Flutter Widgets? #279

Closed RicoLiu closed 2 years ago

RicoLiu commented 2 years ago

Can I use reflectable to reflect Flutter Widgets, such as AppBar, Container etc.

eernstg commented 2 years ago

There should not be anything special about those classes, but you will need to request the reflection support in an indirect manner (because, presumably, you can't edit the declaration of AppBar etc, so you can't directly add metadata like @reflector to those classes).

Check out https://github.com/google/reflectable.dart/blob/master/test_reflectable/test/global_quantify_test.dart to see an example where GlobalQuantifyCapability is used to connect the given reflector to some classes, based on a String argument that matches the class name. You have to put @GlobalQuantifyCapability(...) as metadata on an import of reflectable.dart (that's the only location where this metadata is enabled).

Check out https://github.com/google/reflectable.dart/blob/master/reflectable/doc/TheDesignOfReflectableCapabilities.md for some background information about capabilities.

eernstg commented 2 years ago

I'll close this issue as resolved, please create a new one if further questions about this topic remain.