🥚 Classes
Code your first Dart class
Create a Class
Classes are a way to group data and behavior together, like a blueprint for an Object.
classes.dart
class Basic {
int id;
Basic(this.id);
doStuff() {
print('Hello my ID is $id');
}
}
Create an Object
Use the class to instantiate an Object. The new
keyword is optional.
classes.dart
Basic thing = new Basic(55);
thing.id;
thing.doStuff();
Static Methods
You can call static methods on the class itself without creating a new object.
main.dart
class Basic {
static globalData = 'global';
static helper() {
print('helper');
}
}
Basic.globalData;
Basic.helper();