Static variables
Static variables (class variables) are useful for class-wide state andconstants:
Note: This page follows the style guide recommendation of preferring lowerCamelCase
for constant names.
Static methods
import 'dart:math';
class Point {
num x, y;
static num distanceBetween(Point a, Point b) {
var dx = a.x - b.x;
var dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
}
void main() {
var a = Point(2, 2);
var b = Point(4, 4);
var distance = Point.distanceBetween(a, b);
assert(2.8 < distance && distance < 2.9);
}
Note: Consider using top-level functions, instead of static methods, for common or widely used utilities and functionality.