Apps are full of things: products, customers, orders, farmers, students. Keeping each thing's details together, with the actions that belong to it, makes code easier to read and much harder to break. Dart does this with classes. Dart also protects you from missing values with null safety, which prevents one of the most common causes of app crashes.
Classes and objects
A class is a template. An object is one thing made from that template.
class Product {
final String name;
final double price;
int quantity;
Product(this.name, this.price, this.quantity);
bool get inStock => quantity > 0;
double totalValue() => price * quantity;
}This class has fields (name, price, quantity), a constructor that fills them in, a getter (inStock) and a method (totalValue). Now you can create objects:
var rice = Product('Rice 5kg', 120, 8);
print(rice.inStock); // true
print(rice.totalValue()); // 960.0In Flutter, every screen and widget is a class, so this idea is everywhere. You will also often use in constructors, written with curly braces and the word , so calls read clearly: .