How to get the parameterized type of an instance with Dart and smoke?

Issue

Consider this code:

class Foo {
  List<String> listOfStrings;
}

Using the smoke package, how can I get String by looking at listOfStrings ?

I see we can get a Declaration from a Type, but I don’t see how to get the parameterized type from Declaration.

This is important for, among other things, building a serialization library.

Solution

That’s not currently possible to do in smoke.

It might not even be possible to do with the mirrors API directly either. For example:

import 'dart:mirrors';
class B<T> {}
class A {
  static B<int> b = new B<int>();
}
main() {
  var x = reflectType(A);
  print(x);
  print(x.declarations[#b].type);
}

will print B, but not B<int>.

Answered By – Siggi Cherem

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *