質問

In javascript you can do something like this:

var name = 'myVariableName';
myObject[name] = someValue;

In Dart, can I get variables from class objects by their name as a string? For example

var vector = new Vector3();
vector['x'] = 0.0;
役に立ちましたか?

解決

If you want to access normal fields of an arbitrary object through a string you need to use mirrors (reflection). You need to be careful, though, since mirrors can increase the code-size of the dart2js output considerably if not done carefully.

If you just need a string-value store, then a Map is what you are looking for.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top