I have a class:
class Dog {
Dog() {
print("Current classname is: ${this.className}");
}
}
It seems this.className is not allowed. Is there something equivalent ?
String type = MyClass(). runtimeType. toString();
In the Flutter SDK the . of methods are a kind of service locator function that take the framework BuildContext as an argument and return an internal API related to the named class but created by widgets higher up the widget tree.
Classes, enums, typedefs, and extensions name should be in UpperCamelCase.
To check the type of a variable in Flutter and Dart, you can use the runtimeType property.
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();
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