Last active
December 25, 2018 14:49
-
-
Save JRGGRoberto/3fa05c68aff54ea83cc071b9df2e84d9 to your computer and use it in GitHub Desktop.
Dart Flutter
This file contains 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
class Pessoa { | |
String nome; | |
int idade; | |
double altura; | |
void dormir(){ | |
print("$nome está dormindo!"); | |
} | |
void aniver(){ | |
idade++; | |
} | |
} | |
void main() { | |
Pessoa pessoa1 = new Pessoa(); // new é opcional | |
pessoa1.nome = "Roberto"; | |
pessoa1.idade = 36; | |
pessoa1.altura = 1.82; | |
Pessoa pessoa2 = Pessoa(); | |
pessoa2.nome = "João"; | |
pessoa2.idade = 35; | |
pessoa2.altura =1.83; | |
print(pessoa1.nome); | |
pessoa1.aniver(); | |
print(pessoa1.idade); | |
pessoa2.dormir(); | |
} |
This file contains 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
class Pessoa { | |
String nome; | |
int idade; | |
double altura; | |
void dormir(){ | |
print("$nome está dormindo!"); | |
} | |
void aniver(){ | |
idade++; | |
} | |
Pessoa(this.nome, this.idade, this.altura); | |
Pessoa.nascer(this.nome, this.altura){ | |
this.idade = 0; | |
print("$nome nasceu!!! Nasceu com $altura cm de altura"); | |
dormir(); | |
} | |
} | |
void main() { | |
/* Pessoa pessoa1 = new Pessoa(); // new é opcional | |
pessoa1.nome = "Roberto"; | |
pessoa1.idade = 36; | |
pessoa1.altura = 1.82; | |
*/ | |
Pessoa pessoa1 = new Pessoa("Roberto", 36, 1.82); | |
Pessoa pessoa4 = Pessoa.nascer("Helder", 0.60); | |
/* | |
Pessoa pessoa2 = Pessoa(); | |
pessoa2.nome = "João"; | |
pessoa2.idade = 35; | |
pessoa2.altura =1.83; | |
*/ | |
Pessoa pessoa2 = Pessoa("João", 35, 1.83); | |
Pessoa pessoa3 = Pessoa("Helena", 2, 0.90); | |
print(pessoa3.nome); | |
print(pessoa1.nome); | |
pessoa1.aniver(); | |
print(pessoa1.idade); | |
pessoa2.dormir(); | |
} |
This file contains 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
void main(){ | |
criarBotao("Botao Sair", botaoFeito, cor:"Azul"); | |
print("--"); | |
criarBotao("Botao Camera",(){ | |
print("Botão criado por função anonima"); | |
}); | |
print("--"); | |
criarBotao("Botao Sair", botaoCriado, cor:"Verde"); | |
} | |
void botaoCriado(){ | |
print("Botão criado!!!"); | |
} | |
void botaoFeito(){ | |
print("Botão Feito!!!"); | |
} | |
void criarBotao(String texto, Function criandoFunc, {String cor, double largura}){ | |
print(texto); | |
print(cor ?? "Preto"); | |
print(largura ?? 10); | |
criandoFunc(); | |
} |
This file contains 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
class Animal { | |
String nome; | |
double peso; | |
Animal(this.nome, this.peso); | |
void comer() { | |
print("$nome comeu!"); | |
} | |
void fazerSom() { | |
print("$nome fez algum som!"); | |
} | |
} | |
class Cachorro extends Animal { | |
int fof; | |
Cachorro(String nome, double peso, this.fof) : super(nome, peso); | |
void brincar() { | |
fof += 10; | |
print("Fofura do $nome aumentou para $fof!!!"); | |
} | |
@override | |
void fazerSom() { | |
print("$nome latiu!"); | |
} | |
@override | |
String toString(){ | |
return "Cachorro | Nome: $nome, Peso: $peso, Fofura: $fof"; | |
} | |
} | |
class Gato extends Animal { | |
Gato(String nome, double peso) : super (nome, peso); | |
bool estaAmigavel() { | |
return true; | |
} | |
} | |
void main() { | |
Cachorro cachorro = Cachorro("Dog", 10.3, 100); | |
print(cachorro); | |
cachorro.fazerSom(); | |
cachorro.comer(); | |
cachorro.brincar(); | |
print(""); | |
Gato gato = Gato("Cat", 5.1); | |
print(gato); | |
gato.fazerSom(); | |
gato.comer(); | |
print("${gato.nome} está amigável? ${gato.estaAmigavel()}"); | |
} |
This file contains 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
class Pessoa { | |
String nome; | |
int idade; | |
Pessoa(this.nome, this.idade); | |
} | |
void main() { | |
List<String> nomes = ["Joelma", "Roberto", "Canela"]; | |
print(nomes[0]); | |
nomes.add("Helena"); | |
print(nomes); | |
print(nomes.length); | |
nomes.removeAt(2); | |
print(nomes); | |
nomes.insert(0,"Veleiro"); | |
print(nomes); | |
print(nomes.contains("Helena")); | |
List<Pessoa> pessoas = List(); | |
pessoas.add(Pessoa("Castelo",32)); | |
pessoas.add(Pessoa("Góes",36)); | |
for(Pessoa p in pessoas){ | |
print("${p.nome} tem ${p.idade} anos" ); | |
} | |
} |
This file contains 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
class InfoPessoa { | |
int idade; | |
String localidade; | |
InfoPessoa(this.idade, this.localidade); | |
@override | |
String toString(){ | |
return "$idade anos, região de $localidade"; | |
} | |
} | |
void main() { | |
Map<int, String> ddds = Map(); | |
ddds[11] = "São Paulo"; | |
ddds[13] = "Campinas"; | |
ddds[21] = "Rio de janeiro"; | |
ddds[35121] = "Lisboa"; | |
ddds.remove(11); | |
print(ddds); | |
print(ddds.keys); | |
print(ddds.values); | |
Map<String, dynamic> pessoa = Map(); | |
pessoa["nome"] = "Roberto"; | |
pessoa["idade"] = 36; | |
pessoa["altura"] = 1.82; | |
print(pessoa["nome"]); | |
Map<String, InfoPessoa> pessoas = Map(); | |
pessoas["João"] = InfoPessoa(30, "Realengo"); | |
pessoas["Miguel"] = InfoPessoa(8, "Quintino"); | |
print(pessoas); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment