2-Classes

Classes

void main () {
	// CreaciΓ³n de un objeto
	var ana = Persona("Ana", 30);
	ana.hablar(); // Llama al mΓ©todo hablar
}

class Persona {
  String nombre;
  int edad;

  // Constructor
  Persona(this.nombre, this.edad);

  // MΓ©todo
  void hablar() {
	print("Hola, me llamo $nombre");
  }
}

Dart is an Object Oriented Programming Language, so, in this you must use many classes and methods

Get methods

To code a get method:

class Product {
	int amount
	
	Product(this.amount);
	
	int get amount {
		return $amount;
	}
}

If you want to get in string format:

class Product {
	int amount
	
	Product(this.amount);
	
	String get amount {
		return "$amount"; // This could be between simple or double quation marks
	}
}

Static Methods

class Example {
	static void staticMethodDoesSomething() {
		print("Static Method here!");
	}
}

void main() {
	Example.staticMethodDoesSomething();
}