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

Issue

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 ?

Solution

You can use the getPropertyValue and setProperty methods like

div.style.setProperty(prop, otherdiv.style.getPropertyValue(prop));

Answered By – Günter Zöchbauer

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

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