I have a class:
class Dog {
Dog() {
print("Current classname is: ${this.className}");
}
}
It seems this.className is not allowed. Is there something equivalent ?
this.runtimeType
or just
runtimeType
returns the name of the current class.
If you want to initialize a variable at the beginning of the class and not in the build method (for instance), the way to go is simply doing as follows:
String className = (YourClass).toString();
Please see the attached picture of standalone code that shows an implementation of just getting the class name from this function:
void printArea(Shape shape){
String shapeClass = (shape).runtimeType.toString();
print('The area of the $shapeClass is: ${shape.area}');
}