Class Variables & Methods
This lesson covers Dart's Class level variable(s) and method(s).
Introduction
The variables and methods of a class are shared across all instances of the class. They are not called on any specific object instance of the class.
In the Dart language, there are two ways to implement such variables and methods.
- Using the
static
keyword - Without the
static
keyword
The class-level variable(s) is useful to declare constants and implement a class-wide state. Generally, utility classes use class variables and methods to provide quick and easy access to methods and constants.
With the static
keyword
The static
keyword is used to declare class level variables and methods.
The class methods can be called from other classes using the class names they are defined in.
Let’s take an example of a string utility class ...