In Object-Oriented Programming, getters and setters are special methods that provide access to an object’s properties.
Each property has their implicit getters and setters. You can create your own getters and setters if needed.
class Sale {
final int id;
final String name;
final String status;
double amount;
double get exchangedAmount{
return amount*1.2;
}
set exchangedAmount(double rate){
amount = amount*rate;
}
String get statusText {
Map<String, String> map = {
'draft': 'Draft',
'sent': 'Sent',
'sale': 'Sale',
};
if (map.containsKey(status)) {
return map[status];
}
return status;
}
Sale(this.id, this.name, this.status, this.amount);
}