I understand how to assign a function to a variable in dart but how about a class field? Im currently doing it like this:
class A{
DivElement rootElement;
void addClass(String newClass){
rootElement.classes.add(newClass);
}
}
but I was hoping dart would support doing it a little bit shorter, something like how you would with a regular variable:
class A{
DivElement rootElement;
addClass => rootElement.classes.add;
}
is there a syntax similar to the second code snippet in dart?
You can either call the method or make a getter that returns the actual function:
class A {
DivElement rootElement;
get addClass => rootElement.classes.add;
}
or:
class A {
DivElement rootElement;
addClass(newClass) => rootElement.classes.add(newClass);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With