Skip to content

Instantly share code, notes, and snippets.

@felipecastrosales
Created November 23, 2021 02:30
Show Gist options
  • Save felipecastrosales/a5df36cc51f795440a9a284527b434e0 to your computer and use it in GitHub Desktop.
Save felipecastrosales/a5df36cc51f795440a9a284527b434e0 to your computer and use it in GitHub Desktop.
POO - Getters e Setters
void main() {
var pessoa = Pessoa();
pessoa.altura = 1.85; // ok
pessoa.altura = 5.00; // > 2.5 → 'Altura inválida'
}
class Pessoa {
double? _altura;
double? get altura => _altura;
set altura(double? altura) {
if (altura != null && altura > 0 && altura < 2.5) {
_altura = altura;
} else {
print('Altura inválida');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment