The Dart static keyword is used to declare the class variables and methods. The static variables/methods belong to the class instead of individual objects.
Dart static keyword
When we declare the data member as static, we can access it without creating an object of the class. The static variables/methods are the same for every class object. To access the static method or variable we can put the class name before the static variable or method.
We use the static keyword to declare a variable or a method inside the class. A static variable is treated the same for all instances of the class; it means a single copy of the static variable is shared among all the instances of the class. The memory is allocated when the class is loaded and is used for the entire program’s life.
Declare static variable
A static variable is also known as the class variable. We can declare the static variable by using the static keyword followed by the data type and the variable name.
static data_type variable_name;
static data_type variable_name = <initialization> ;
static int number = 10;
Access static Variable
We can access the static variable by using the class name itself instead of creating an object of it.
The general syntax to access the static variable is as follows:
The static members are bound to the class itself and not to the instances of the class. Therefore, they are commonly used for constants or utility functions that are not related to the class objects.
Dart tutorial on this website can be found at:
More information on Dart: