How to reflect on a class from an imported package with a private constructor?

509 Views Asked by At

I am using the reflectable library to reflect on types from imported packages (like analysis_server_client or flutter). I can reflect on types that have public constructors like Notification or Request (from the analysis_server_client package). I reflect on those types by extending those types and then using the superclassQuantifyCapability capability.

However, I am not able to reflect on types that have a private constructor like Icons (from the flutter package) since I cannot extend them. Is there a way to reflect on types like Icons that have a private constructor?

1

There are 1 best solutions below

0
fertrig On

I figured it out. You have to use the GlobalQuantifyCapability which lets you declare which members to generate reflection on. It works on classes with private constructors as well. Some sample code:

@GlobalQuantifyCapability(r"^.(SomeClass|SomeEnum)", reflector)
import 'package:reflectable/reflectable.dart';

import 'package:some_package/some_class.dart';
import 'package:some_package/some_enum.dart';

class Reflector extends Reflectable {
  const Reflector() : super(declarationsCapability, ...);
}
const reflector = const Reflector();