Class Description
A class is an object that has content (value/parameter) to describe the class itself.
Analogy:
Let's say a class is a room in a school, so the contents (value/parameter) of the room are: desks, chairs, blackboards, students, teachers, etc.
Illustration:
Parameters in a class can be a logic or just a variable.
Sample code:
room class{
Teacher string = "Budi";
List of students = [
"Share",
"Samsul",
"Rukmini"
];
}
Class Characteristics
If you are completely new to darts programming, the following two things are important points to know
1. Class is written with the pattern CamelCase, which means it starts with an uppercase letter.
2. If there is a class that uses underscore (_) , then that class is private class.
Constructor
Constructor is a parameter a class, to send or initialize data from other methods/or logic. The constructor itself is required (required), or not required (optional), or even optional required. The explanation is in the points below.
Required Constructor
The following is an example of a constructor that is required (required)
room class{
teacher strings;
list of students;
Room(this.teacher, this.student); //required constructor
}
How to call or initialize data:
Room("Budi", ["Agus", "Arthur", " Gilang"])
Optional Constructor
The following is an example of an optional constructor (optional)
room class{
teacher strings;
list of students;
Room({this.teacher:"", this.student: const []});//optional constructor
}
How to call or initialize data
Room(teacher: "budi", student: ["Agus", "Arthur ", "Gilang"]);
Optional Required Constructor
This constructor only applies to dart programming languages that are null_safety, ie version 2.12 or above.
Example of writing:
room class{
teacher strings;
list of students;
Room({required this.teacher, required this.student});//optional required constructor
}