Dart Static Method
Overview
Let’s understand the concept of the Dart static method in this tutorial. The static methods are the member of the class instead of the class instance. The static methods can use only static variables and can invoke the static methods of the class. We don’t need to create an instance of class the access it. The static method is useful when we want to use it in other classes.
Declare static Method
We can declare the static method by using the static keyword followed by the method name with the method return type.
The general syntax to declare a static method is as follows:
static return_type method_name() {
// static method statement(s)
}
Calling Static Method
We can access static methods using the class name. We can invoke the static method using the class name with a dot operator and the static method name.
The general syntax to access the static method is as follows:
ClassName.staticMethod();
Static methods are also known as class methods. The static methods are the members of the class instead of its object. A single copy of the static method is shared among all the instances of a class.
—
Dart Tutorials
Dart tutorial on this website can be found at:
https://www.testingdocs.com/dart-tutorials-for-beginners/
More information on Dart: