Created
November 13, 2021 00:43
-
-
Save felipecastrosales/3dd6d067b921df408ca46daafad0fb46 to your computer and use it in GitHub Desktop.
Modificadores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. - `const`: variável inicializada em tempo de compilação; | |
// torna-se imutável - immutable -; | |
// seu valor não pode ser alterado. | |
// → Quando temos valores e componentes que não mudam: localização de imagens locais, estilizações de texto, componentes que não se alteram no layout e et cetera. | |
// | |
// 2. - `final`: variável inicializada em tempo de execução; | |
// seu valor deve ser inicializado e não pode ser alterado. | |
// → Leitura de arquivos, respostas vindas da internet, execuções feitas durante o uso da aplicação, et cetera. | |
// | |
// 3. - `late`: a variável é inicializada como Non-Nullable e deve ser inicializada após sua declaração; | |
// fazendo a inicialização tardia - lazy initialization. | |
// → Deve ser inicializada sempre antes de utilizada. | |
late double calculo; | |
void main() { | |
// 1. | |
const dataNascimento = '23-05-2017'; | |
print('Nasceu em: $dataNascimento'); | |
// 2. | |
final time = DateTime.now(); | |
print('Agora é exatamente: $time'); | |
// 3. | |
calculo = calculando(); | |
print(calculo); | |
} | |
double calculando() { | |
print('Cálculo é: $calculo'); | |
return 7.0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment