Questions tagged [dart-mirrors]

Dart Mirrors lets you reflect objects with an API that is based on the concept of mirrors.

Dart Mirrors lets you reflect objects with an API that is based on the concept of mirrors.

To use reflection on an object, you need to get a mirror for it first.

An introducion into Dart Mirrors.

dart:mirrors library

161 questions
6
votes
2 answers

Under what circumstances does reflectClass(o.runtimeType) return a different result from reflect(o).type?

from the dartdocs for InstanceMirror.type: "Returns a mirror on the actual class of the reflectee. The class of the reflectee may differ from the object returned by invoking runtimeType on the reflectee." so under what circumstances does…
Daniel Robinson
  • 11,116
  • 12
  • 52
  • 92
6
votes
1 answer

How to get default value of a field in an abstract class

Suppose I have a class like this: abstract class Foo { String name bar = 'bar'; } Using mirror, can we get the value of bar ?
Budi Sutrisno
  • 469
  • 4
  • 11
6
votes
4 answers

How to use dart to implement a delegate/proxy?

I have two classes Parser and Proxy, and when I invoke a method from Parser, which does not exist, it will delegate it to Proxy class. My code: class Parser { noSuchMethod(Invocation invocation) { // how to pass the `invocation` to…
Freewind
  • 177,284
  • 143
  • 381
  • 649
6
votes
2 answers

How do I get all fields for a class in Dart?

I looked at the dart:mirrors library, and I found ClassMirror. While I saw getField I didn't see access to all fields. I did see getters, though. If I want to get all fields for a class, do I have to go through getters ?
Seth Ladd
  • 77,313
  • 56
  • 165
  • 258
5
votes
1 answer

How to add key value-pair to a Object?

I want to update my Object by adding a more key-value pair. Object options = { "first_name": "Nitish", "last_name" : "Singh" } after initializing the Object I want to add one more key and value. Is there any way to do this. after adding one…
nitishk72
  • 1,083
  • 2
  • 8
  • 19
5
votes
1 answer

how to enable --enable-experimental-mirrors in dart build?

My build of my projects are failing because they rely on mirrors and dart build out put tells me to use --enable-experimental-mirrors to try to use mirrors in dart2js code as it is. so if I run pub build --enable-experimental-mirrors all I get is…
Daniel Robinson
  • 11,116
  • 12
  • 52
  • 92
5
votes
2 answers

Populating a parent field dynamically in Dart

I'm creating objects dynamically from Map data, populating fields for matching key names. The problem comes when fields are defined on the parent, where attempting to set a value on a parent field produces the error: No static setter 'name'…
Todd Chambery
  • 2,278
  • 4
  • 17
  • 26
5
votes
2 answers

in Dart, problems with static method when called from variable

have class Klass with static method fn1 class Klass { static String fn1() => 'hello'; } > Klass.fn1(); // hello but when Klass is assigned to a variable, calling the method fn1 fails var k = Klass; > k.fn1() // "Unhandled exception: Class…
cc young
  • 15,035
  • 25
  • 76
  • 138
5
votes
2 answers

Conditional imports / code for Dart packages

Is there any way to conditionally import libraries / code based on environment flags or target platforms in Dart? I'm trying to switch out between dart:io's ZLibDecoder / ZLibEncoder classes and zlib.js based on the target platform. There is an…
ALW
  • 987
  • 8
  • 13
5
votes
2 answers

how to invoke class form dart library string or file

who to invoke class form dart library string or file? for example for-load.dart file class TestLoad { void requestHandler(){ } } then main.dart file main(){ //this get load lib var lib =…
5
votes
1 answer

Dart, how to parse user string into functional dart code?

is it possible to parse in a user entered string, say from a text area, and then incorporate it into a dart function which you can then run, without having to post it back to the server? I guess I'm looking for a dart eval equivalent.
Daniel Robinson
  • 11,116
  • 12
  • 52
  • 92
5
votes
3 answers

@override of Dart code

I noticed PetitParserDart has a lot of @override in the code, but I don't know how do they be checked? I tried IDEA dart-plugin for @override, but it has no effect at all. How can we use @override with Dart?
Freewind
  • 177,284
  • 143
  • 381
  • 649
5
votes
3 answers

How can I use Reflection (Mirrors) to access the method names in a Dart Class?

I need to "fetch" the methods in a Dart Class. How can I do this? And I want to be able to call the methods. May I see an example?
george koller
  • 2,363
  • 3
  • 17
  • 26
4
votes
2 answers

How do I get all the fields of an object (including its superclass), using Dart's Mirrors API?

Given two Dart classes like: class A { String s; int i; bool b; } class B extends A { double d; } And given an instance of B: var b = new B(); How do I get all the fields in the b instance, including fields from its superclass?
Seth Ladd
  • 77,313
  • 56
  • 165
  • 258
4
votes
1 answer

custom annotation / Metadata in dart lang

Can any one explain me the use of annotations in Dart? In the documentations, I found this example: library todo; class todo { final String who; final String what; const todo(this.who, this.what); } followed by import…
Hasan A Yousef
  • 15,770
  • 15
  • 88
  • 140
1
2
3
10 11