8.0 Klasy

Klasy w darcie deklaruje się przy użyciu słowa class ich składnia jest zblizona do tej z jęzku Java ,więc zbytrnio nie będę wyjaśniał tej częsci ,ten sam podział na metody i pola
void main(){
  //1 sposób
  var Student1=Student();
  Student1.wiek=21;
  Student1.pokaz();
   //2 sposób
  Student Student2=new Student();
  Student2.wiek=22;
  Student2.pokaz();
   //Operator new jest opcjonalny
   var Student3=new Student();
  Student3.wiek=23;
  Student3.pokaz();
  
 
}
//Deklaraja naszej prostej klasy
class Student{
  int wiek;
  void pokaz(){
    print(wiek);
  }
}

8.1 Gettery i Settery

Przydatne do tworzenia modeu danych get , set
void main() {

  var student = Student();
  student.name = "Peter";     // Calling default Setter to set value
  print(student.name);        // Calling default Getter to get value

  student.percentage = 438.0;   // Calling Custom Setter to set value
  print(student.percentage);    // Calling Custom Getter to get value
}

class Student {

  String name;        // Instance Variable with default Getter and Setter 

  double _percent;    // Private Instance Variable for its own library   

  // Instance variable with Custom Setter
  void set percentage(double marksSecured) => _percent = (marksSecured / 500) * 100;
  // Instance variable with Custom Getter
  double get percentage => _percent;
}