-
Notifications
You must be signed in to change notification settings - Fork 0
/
41-Enums.dart
37 lines (28 loc) · 986 Bytes
/
41-Enums.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// ENUMS
void main(){
final employee1 =Employee('Valdemar', EmployeeType.swe);
final employee2 = Employee('Fulano', EmployeeType.finance);
final employee3 = Employee('Sonal', EmployeeType.marketing);
employee1.fn();
employee2.fn();
employee3.fn();
}
enum EmployeeType {
swe,finance,marketing // obrigatoriamente precisam comecar com minusculas
}
class Employee {
final String name;
final EmployeeType type;
Employee (this.name,this.type);
void fn() { // essa funcao com switch exige que todos os cases do switch sejam
switch (type) { // tratados. Se tiver um caso sem previsao, o compilador gera erro
case EmployeeType.swe:
print('Software Engineer');
case EmployeeType.finance:
print('Finance');
//case EmployeeType.marketing:
default: // ou voce trata caso a caso do switch ou faz um caso default
print('Marketing');
}
}
}