How do I get the qualified name from a Type instance, in Dart?


I have a instance of Type, but I want its fully qualified name. How can I do this? I know I have to use Mirrors (Dart’s reflection library).


Use the new reflectClass top-level function from dart:mirrors.

Here’s an example:

import 'dart:html';
import 'dart:mirrors';

class Awesome {
  // ...

void main() {
  var awesome = new Awesome();
  Type type = awesome.runtimeType;
  ClassMirror mirror = reflectClass(type);
  Symbol symbol = mirror.qualifiedName;
  String qualifiedName = MirrorSystem.getName(symbol);

  query('#name').text = qualifiedName;

The qualifiedName should be something like:

Note, this works in build 21753 or higher. Also, this doesn’t currently work in dart2js yet. We plan to support it in dart2js.

Answered By – Seth Ladd

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.