Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get access to an object's property using bracket notation in dart

I try to do the following:

var properties = ["height" , "width"];
for (var prop in properties){
  div.style[prop] = otherdiv.style[prop];
}

But dart doesn't seem to accept this bracket notation, is there any other way to access a property using a string in dart ?

like image 706
90intuition Avatar asked Feb 01 '15 12:02

90intuition


People also ask

How do you access the property of an object in DART?

For general Dart objects, there is no way to access properties from a computed name. That's a deliberate language choice - it makes it possible to optimize object layout differently when it doesn't have to allow unpredictable access.

How do you dynamically access an object?

To access the object property dynamically in JS, you need to pass the property name as a string in square brackets. As the value of the variable key changed, we got access to the different properties of the user object. The most common way to access the object properties in JavaScript is the dot.


1 Answers

You can use the getPropertyValue and setProperty methods like

div.style.setProperty(prop, otherdiv.style.getPropertyValue(prop));
like image 138
Günter Zöchbauer Avatar answered Oct 07 '22 15:10

Günter Zöchbauer