├── controle ├── break_continue.dart ├── desafio_for.dart ├── desafio_if_else.dart ├── for_1.dart ├── for_2.dart ├── for_3.dart ├── if_else.dart ├── switch.dart └── while.dart ├── funcao ├── basico_1.dart ├── basico_2.dart ├── dinamico.dart ├── filtro_1.dart ├── filtro_2.dart ├── filtro_3.dart ├── funcao_com_generics.dart ├── funcao_como_parametro_1.dart ├── funcao_como_parametro_2.dart ├── funcao_em_variavel_1.dart ├── funcao_em_variavel_2.dart ├── map_reduce_1.dart ├── map_reduce_2.dart ├── map_reduce_3.dart ├── nomeados.dart ├── opcional.dart └── retornar_funcao.dart ├── fundamentos ├── constantes_1.dart ├── constantes_2.dart ├── generics.dart ├── interpolacao.dart ├── notacao_ponto.dart ├── operadores_1.dart ├── operadores_2.dart ├── operadores_3.dart ├── operadores_4.dart ├── primeiro.dart ├── tipos_basicos_1.dart ├── tipos_basicos_2.dart ├── variaveis_1.dart └── variaveis_2.dart └── oo ├── modelo ├── carro.dart ├── cliente.dart ├── data.dart ├── produto.dart ├── venda.dart └── venda_item.dart └── teste ├── teste_carro.dart ├── teste_data.dart └── teste_venda.dart /controle/break_continue.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | 4 | for(int a = 0; a < 10; a++) { 5 | if(a == 6) { 6 | break; 7 | } 8 | print(a); 9 | } 10 | 11 | print('Depois do laço for #01'); 12 | 13 | for(int a = 0; a < 10; a++) { 14 | if(a % 2 == 1) { 15 | continue; 16 | } 17 | print(a); 18 | } 19 | 20 | print('Depois do laço for #02'); 21 | } -------------------------------------------------------------------------------- /controle/desafio_for.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | 4 | for(var valor = '#'; valor != '#######'; valor += '#') { 5 | print(valor); 6 | } 7 | } -------------------------------------------------------------------------------- /controle/desafio_if_else.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | var nota = 0.3; 4 | 5 | if(nota >= 9.0) // ; NÃO USA ; EM ESTRUTURAS DE CONTROLE * 6 | { 7 | print('Parabéns! Vc foi brilhante!'); 8 | } 9 | 10 | // * EXCEÇÃO DO/WHILE!!! 11 | } -------------------------------------------------------------------------------- /controle/for_1.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | 3 | for(int a = 1; a <= 10; a += 2) { 4 | print('a = $a'); 5 | } 6 | 7 | for(int a = 100; a >= 0; a -= 4) { 8 | print("a = $a"); 9 | } 10 | 11 | int b = 0; 12 | for(; b <= 10; b++) { 13 | print('b = $b'); 14 | } 15 | 16 | print('[FORA] b = $b'); 17 | 18 | var notas = [8.9, 9.3, 7.8, 6.9, 9.1]; 19 | for(var i = 0; i < notas.length; i++) { 20 | print("Nota ${i + 1} = ${notas[i]}."); 21 | } 22 | 23 | print('Fim!'); 24 | } -------------------------------------------------------------------------------- /controle/for_2.dart: -------------------------------------------------------------------------------- 1 | // for in 2 | 3 | main() { 4 | var notas = [8.9, 9.3, 7.8, 6.9, 9.1]; 5 | 6 | for(var nota in notas) { 7 | print("O valor da nota é $nota."); 8 | } 9 | 10 | var coordenadas = [ 11 | [1, 3], 12 | [9, 1], 13 | [19, 23], 14 | [2, 14], 15 | ]; 16 | 17 | for(var coordenada in coordenadas) { 18 | for(var ponto in coordenada) { 19 | print("Valor do ponto é $ponto"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /controle/for_3.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | Map notas = { 3 | 'João Pedro': 9.1, 4 | 'Maria Augusta': 7.2, 5 | 'Ana Silva': 6.4, 6 | 'Roberto Andrade': 8.8, 7 | 'Pedro Firmino': 9.9, 8 | }; 9 | 10 | for(String nome in notas.keys) { 11 | print("Nome do aluno é $nome e a nota é ${notas[nome]}"); 12 | } 13 | 14 | for(var nota in notas.values) { 15 | print("A nota é $nota"); 16 | } 17 | 18 | for(var registro in notas.entries) { 19 | print("O ${registro.key} tem nota ${registro.value}."); 20 | } 21 | } -------------------------------------------------------------------------------- /controle/if_else.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | main() { 4 | var nota = Random().nextInt(11); 5 | print("Nota selecionada foi $nota."); 6 | 7 | if(nota >= 9) { 8 | print('Quadro de Honra!'); 9 | } else if(nota >= 7) { 10 | print('Aprovado!'); 11 | } else if(nota >= 5) { 12 | print('Recuperação!'); 13 | } else if(nota >= 4) { 14 | print('Recuperação + Trabalho!'); 15 | } else { 16 | print('Reprovado!'); 17 | } 18 | } -------------------------------------------------------------------------------- /controle/switch.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | main() { 4 | var nota = Random().nextInt(11); 5 | print('A nota sorteada foi $nota.'); 6 | 7 | switch(nota) { 8 | case 10: 9 | case 9: 10 | print('Quadro de Honra!'); 11 | print('Parabéns!'); 12 | break; 13 | case 8: 14 | case 7: 15 | print('Aprovado!'); 16 | break; 17 | case 6: 18 | case 5: 19 | case 4: 20 | print('Recuperação!'); 21 | break; 22 | case 3: 23 | case 2: 24 | case 1: 25 | case 0: 26 | print('Reprovado!'); 27 | break; 28 | default: 29 | print('Nota inválida!'); 30 | } 31 | 32 | print('Fim!'); 33 | } -------------------------------------------------------------------------------- /controle/while.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | main() { 4 | var digitado = 'sair'; 5 | 6 | while(digitado != 'sair') { 7 | stdout.write('Digite algo ou sair: '); 8 | digitado = stdin.readLineSync(); 9 | } 10 | 11 | do { 12 | stdout.write('Digite algo ou sair: '); 13 | digitado = stdin.readLineSync(); 14 | } while(digitado != 'sair'); 15 | 16 | print('Fim!'); 17 | } -------------------------------------------------------------------------------- /funcao/basico_1.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | void main() { 4 | somaComPrint(2, 3); 5 | 6 | int c = 4; 7 | int d = 5; 8 | somaComPrint(c, d); 9 | 10 | somaDoisNumerosQuaisquer(); 11 | } 12 | 13 | void somaComPrint(int a, int b) { 14 | print(a + b); 15 | } 16 | 17 | void somaDoisNumerosQuaisquer() { 18 | int n1 = Random().nextInt(11); 19 | int n2 = Random().nextInt(11); 20 | print('Os valores sorteados foram: $n1 e $n2.'); 21 | print(n1 + n2); 22 | } -------------------------------------------------------------------------------- /funcao/basico_2.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | main() { 4 | int resultado = somar(2, 3); 5 | resultado *= 2; 6 | 7 | print("O dobro do resultado é $resultado"); 8 | 9 | print("O resultado é ${somarNumerosAleatorios()}"); 10 | } 11 | 12 | int somar(int a, int b) { 13 | return a + b; 14 | } 15 | 16 | int somarNumerosAleatorios() { 17 | int a = Random().nextInt(11); 18 | int b = Random().nextInt(11); 19 | return a + b; 20 | } -------------------------------------------------------------------------------- /funcao/dinamico.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | juntar(1, 9); 4 | juntar('Bom ', 'dia!!!'); 5 | var resultado = juntar('O valor de PI é ', 3.1415); 6 | print(resultado.toUpperCase()); 7 | } 8 | 9 | String juntar(dynamic a, b) { 10 | print(a.toString() + b.toString()); 11 | return a.toString() + b.toString(); 12 | } -------------------------------------------------------------------------------- /funcao/filtro_1.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | var notas = [8.2, 7.1, 6.2, 4.4, 3.9, 8.8, 9.1, 5.1]; 3 | var notasBoas = []; 4 | 5 | for(var nota in notas) { 6 | if(nota >= 7) { 7 | notasBoas.add(nota); 8 | } 9 | } 10 | 11 | var notasMuitoBoas = []; 12 | 13 | for(var nota in notas) { 14 | if(nota >= 8.8) { 15 | notasMuitoBoas.add(nota); 16 | } 17 | } 18 | 19 | print(notas); 20 | print(notasBoas); 21 | print(notasMuitoBoas); 22 | } -------------------------------------------------------------------------------- /funcao/filtro_2.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | var notas = [8.2, 7.1, 6.2, 4.4, 3.9, 8.8, 9.1, 5.1]; 3 | 4 | var notasBoasFn = (double nota) => nota >= 7; 5 | var notasMuitoBoasFn = (double nota) => nota >= 8.8; 6 | 7 | var notasBoas = notas.where(notasBoasFn); 8 | var notasMuitoBoas = notas.where(notasMuitoBoasFn); 9 | 10 | print(notas); 11 | print(notasBoas); 12 | print(notasMuitoBoas); 13 | } -------------------------------------------------------------------------------- /funcao/filtro_3.dart: -------------------------------------------------------------------------------- 1 | 2 | List filtrar(List lista, bool Function(E) fn) { 3 | List listaFiltrada = []; 4 | for(E elemento in lista) { 5 | if(fn(elemento)) { 6 | listaFiltrada.add(elemento); 7 | } 8 | } 9 | return listaFiltrada; 10 | } 11 | 12 | main() { 13 | var notas = [8.2, 7.3, 6.8, 5.4, 2.7, 9.3]; 14 | var boasNotasFn = (double nota) => nota >= 7.5; 15 | 16 | var somenteNotasBoas = filtrar(notas, boasNotasFn); 17 | print(somenteNotasBoas); 18 | 19 | var nomes = ['Ana', 'Bia', 'Rebeca', 'Gui', 'João']; 20 | var nomesGrandesFn = (String nome) => nome.length >= 5; 21 | print(filtrar(nomes, nomesGrandesFn)); 22 | } -------------------------------------------------------------------------------- /funcao/funcao_com_generics.dart: -------------------------------------------------------------------------------- 1 | Object segundoElementoV1(List lista) { 2 | return lista.length >= 2 ? lista[1] : null; 3 | } 4 | 5 | E segundoElementoV2(List lista) { 6 | return lista.length >= 2 ? lista[1] : null; 7 | } 8 | 9 | main() { 10 | var lista = [3, 6, 7, 12, 45, 78, 1]; 11 | 12 | print(segundoElementoV1(lista)); 13 | 14 | int segundoElemento = segundoElementoV2(lista); 15 | print(segundoElemento); 16 | 17 | segundoElemento = segundoElementoV2(lista); 18 | print(segundoElemento); 19 | } -------------------------------------------------------------------------------- /funcao/funcao_como_parametro_1.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | void executar({Function fnPar, Function fnImpar}) { 4 | var sorteado = Random().nextInt(10); 5 | print('O valor sorteado foi $sorteado'); 6 | sorteado % 2 == 0 ? fnPar() : fnImpar(); 7 | } 8 | 9 | main() { 10 | var minhaFnPar = () => print('Eita! O valor é par!'); 11 | var minhaFnImpar = () => print('Legal! O valor é ímpar!'); 12 | 13 | executar(fnImpar: minhaFnImpar, fnPar: minhaFnPar); 14 | } -------------------------------------------------------------------------------- /funcao/funcao_como_parametro_2.dart: -------------------------------------------------------------------------------- 1 | int executarPor(int qtde, String Function(String) fn, String valor) { 2 | String textoCompleto = ''; 3 | for(int i = 0; i < qtde; i++) { 4 | textoCompleto += fn(valor); 5 | } 6 | return textoCompleto.length; 7 | } 8 | 9 | main() { 10 | print('Teste'); 11 | var meuPrint = (String valor) { 12 | print(valor); 13 | return valor; 14 | }; 15 | 16 | int tamanho = executarPor(10, meuPrint, 'Muito legal'); 17 | print('O tamanho da string é $tamanho'); 18 | } -------------------------------------------------------------------------------- /funcao/funcao_em_variavel_1.dart: -------------------------------------------------------------------------------- 1 | int somaFn(int a, int b) { 2 | return a + b; 3 | } 4 | 5 | main() { 6 | // tipo nome = valor; 7 | int Function(int, int) soma1 = somaFn; 8 | print(soma1(20, 313)); 9 | 10 | var soma2 = ([int x = 1, int y = 1]) { 11 | return x + y; 12 | }; 13 | print(soma2(20, 313)); 14 | print(soma2(20)); 15 | print(soma2()); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /funcao/funcao_em_variavel_2.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | var adicao = (int a, int b) => a + b; 3 | var subtracao = (int a, int b) => a - b; 4 | var multiplicacao = (int a, int b) => a * b; 5 | var divisao = (int a, int b) => a / b; 6 | 7 | print(adicao(4, 19)); 8 | print(subtracao(9, 13)); 9 | print(multiplicacao(9, 13)); 10 | print(divisao(9, 13)); 11 | } -------------------------------------------------------------------------------- /funcao/map_reduce_1.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | var alunos = [ 3 | {'nome': 'Alfredo', 'nota': 9.9}, 4 | {'nome': 'Wilson', 'nota': 9.3}, 5 | {'nome': 'Mariana', 'nota': 8.7}, 6 | {'nome': 'Guilherme', 'nota': 8.1}, 7 | {'nome': 'Ana', 'nota': 7.6}, 8 | {'nome': 'Ricardo', 'nota': 6.8}, 9 | ]; 10 | 11 | String Function(Map) pegarApenasONome = (aluno) => aluno['nome']; 12 | int Function(String) qtdeDeLetras = (texto) => texto.length; 13 | int Function(int) dobro = (numero) => numero * 2; 14 | 15 | var resultado = alunos 16 | .map(pegarApenasONome) 17 | .map(qtdeDeLetras) 18 | .map(dobro); 19 | 20 | print(resultado); 21 | } -------------------------------------------------------------------------------- /funcao/map_reduce_2.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | var notas = [7.3, 5.4, 7.7, 8.1, 5.5, 4.9, 9.1, 10.0]; 3 | var total = notas.reduce(somar); 4 | print(total); 5 | 6 | var nomes = ['Ana', 'Bia', 'Carlos', 'Daniel', 'Maria', 'Pedro']; 7 | print(nomes.reduce(juntar)); 8 | } 9 | 10 | double somar(double acumulador, double elemento) { 11 | print("$acumulador $elemento"); 12 | return acumulador + elemento; 13 | } 14 | 15 | String juntar(String acumulador, String elemento) { 16 | print("$acumulador => $elemento"); 17 | return "$acumulador,$elemento"; 18 | } -------------------------------------------------------------------------------- /funcao/map_reduce_3.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | var alunos = [ 3 | {'nome': 'Alfredo', 'nota': 9.9}, 4 | {'nome': 'Wilson', 'nota': 9.3}, 5 | {'nome': 'Mariana', 'nota': 8.7}, 6 | {'nome': 'Guilherme', 'nota': 8.1}, 7 | {'nome': 'Ana', 'nota': 7.6}, 8 | {'nome': 'Ricardo', 'nota': 6.8}, 9 | ]; 10 | 11 | var notasFinais = alunos 12 | .map((aluno) => aluno['nota']) 13 | .map((nota) => (nota as double).roundToDouble()) 14 | .where((nota) => nota >= 8.5); 15 | 16 | var total = notasFinais.reduce((t, a) => t + a); 17 | 18 | print("O valor da média é: ${total / notasFinais.length}."); 19 | } -------------------------------------------------------------------------------- /funcao/nomeados.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | saudarPessoa(nome: "João", idade: 33); 3 | saudarPessoa(idade: 47, nome: "Maria"); 4 | 5 | imprimirData(7); 6 | imprimirData(7, ano: 2020); 7 | imprimirData(7, ano: 2021, mes: 12); 8 | } 9 | 10 | saudarPessoa({String nome, int idade}) { 11 | print("Olá $nome nem parece que vc tem $idade anos."); 12 | } 13 | 14 | imprimirData(int dia, {int ano = 1970, int mes = 1}) { 15 | print('$dia/$mes/$ano'); 16 | } -------------------------------------------------------------------------------- /funcao/opcional.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | main() { 4 | int n1 = numeroAleatorio(100); 5 | print(n1); 6 | 7 | int n2 = numeroAleatorio(); 8 | print(n2); 9 | 10 | imprimirData(10, 12, 2020); 11 | imprimirData(10, 12); 12 | imprimirData(10); 13 | } 14 | 15 | int numeroAleatorio([int maximo = 11]) { 16 | return Random().nextInt(maximo); 17 | } 18 | 19 | imprimirData(int dia, [int mes = 1, int ano = 1970]) { 20 | print('$dia/$mes/$ano'); 21 | } -------------------------------------------------------------------------------- /funcao/retornar_funcao.dart: -------------------------------------------------------------------------------- 1 | 2 | int Function(int) somaParcial(int a) { 3 | int c = 0; 4 | 5 | return (int b) { 6 | return a + b + c; 7 | }; 8 | } 9 | 10 | main() { 11 | print(somaParcial(2)(10)); 12 | 13 | var somaCom10 = somaParcial(10); 14 | 15 | print(somaCom10(3)); 16 | print(somaCom10(7)); 17 | print(somaCom10(19)); 18 | } -------------------------------------------------------------------------------- /fundamentos/constantes_1.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'dart:io'; 3 | 4 | main() { 5 | // Área da circunferência = PI * raio * raio 6 | 7 | const PI = 3.1415; 8 | 9 | stdout.write("Informe o raio: "); 10 | final entradaDoUsuario = stdin.readLineSync(); 11 | final double raio = double.parse(entradaDoUsuario); 12 | 13 | // entradaDoUsuario = ""; 14 | 15 | final area = PI * raio * raio; 16 | print("O valor da área é: " + area.toString()); 17 | } -------------------------------------------------------------------------------- /fundamentos/constantes_2.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | 3 | var lista = const ['Ana', 'Lia', 'Gui']; 4 | // lista = const ['Banana', 'Maça']; 5 | 6 | lista.add('Rebeca'); 7 | print(lista); 8 | } -------------------------------------------------------------------------------- /fundamentos/generics.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | print('Início'); 3 | 4 | List frutas = ['banana', 'maça', 'laranja']; 5 | frutas.add('melão'); 6 | 7 | print(frutas); 8 | 9 | Map salarios = { 10 | 'gerente': 19345.78, 11 | 'vendedor': 16345.80, 12 | 'estagiário': 600.00, 13 | }; 14 | 15 | print(salarios); 16 | } -------------------------------------------------------------------------------- /fundamentos/interpolacao.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | String nome = 'João'; 3 | String status = 'aprovado'; 4 | double nota = 9.2; 5 | 6 | String frase1 = nome + " está " + status + " pq tirou nota " + nota.toString() + "!"; 7 | String frase2 = "$nome está $status pq tirou nota $nota!"; 8 | 9 | print(frase1); 10 | print(frase2); 11 | 12 | print("30 * 30 = ${30 * 30}"); 13 | } -------------------------------------------------------------------------------- /fundamentos/notacao_ponto.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | double nota = 6.99.roundToDouble(); 3 | print(nota); 4 | 5 | print("Texto".toUpperCase()); 6 | 7 | String s1 = "leonardo leitão"; 8 | String s2 = s1.substring(0, 8); 9 | String s3 = s2.toUpperCase(); 10 | String s4 = s3.padRight(15, "!"); 11 | 12 | var s5 = "leonardo leitão" 13 | .substring(0, 8) 14 | .toUpperCase() 15 | .padRight(15, '!'); 16 | 17 | print(s4); 18 | print(s5); 19 | } -------------------------------------------------------------------------------- /fundamentos/operadores_1.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | 3 | // Operadores Aritméticos (binário/infix) 4 | int a = 7; 5 | int b = 3; 6 | int resultado = a + b; 7 | 8 | print(resultado); 9 | print(a - b); 10 | print(a * b); 11 | print(a / b); 12 | print(a % b); 13 | print(33 % 2); 14 | print(34 % 2); 15 | print(a + (b * a) - (b / a)); 16 | 17 | // Operadores Lógicos 18 | bool ehFragil = true; 19 | bool ehCaro = true; 20 | 21 | print(ehFragil && ehCaro); // AND -> E 22 | print(ehFragil || ehCaro); // OR -> OU 23 | print(ehFragil ^ ehCaro); // XOR -> OU Exclusivo 24 | print(!ehFragil); // NOT -> Unário/Prefix 25 | print(!!ehCaro); 26 | } -------------------------------------------------------------------------------- /fundamentos/operadores_2.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | 3 | // Operadores Atribuição (binário/infix) 4 | double a = 2; 5 | a = a + 3; 6 | a += 3; 7 | a -= 3; 8 | a *= 3; 9 | a /= 5; 10 | a %= 2; 11 | 12 | print(a); 13 | 14 | // Operadores Relacionais (binário/infix) -> O resultado sempre é BOOL 15 | print(3 > 2); 16 | print(3 >= 3); 17 | print(3 < 4); 18 | print(3 <= 3); 19 | print(3 != 3); 20 | print(3 == 3); 21 | print(3 == '3'); 22 | 23 | 24 | print(2 + 5 > 3 - 1 && 4 + 7 != 7 - 4); 25 | 26 | // 101 = 5 27 | // 100 = 4 28 | // 100 = 4 29 | print(5 & 4); 30 | } -------------------------------------------------------------------------------- /fundamentos/operadores_3.dart: -------------------------------------------------------------------------------- 1 | main() { 2 | 3 | int a = 3; 4 | int b = 4; 5 | 6 | // Operadores Unários 7 | a++; // Posfix 8 | --a; // Prefix 9 | 10 | print(a); 11 | 12 | print(a++ == --b); 13 | print(a == b); 14 | 15 | // Operador Lógico Unário (NOT) 16 | print(!true); 17 | print(!false); 18 | 19 | bool x = false; 20 | print(!x); 21 | } -------------------------------------------------------------------------------- /fundamentos/operadores_4.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | main() { 4 | stdout.write("Está chovendo? (s/N) "); 5 | bool estaChovendo = stdin.readLineSync() == "s"; 6 | 7 | stdout.write("Está frio? (s/N) "); 8 | bool estaFrio = stdin.readLineSync() == "s"; 9 | 10 | String resultado = estaChovendo && estaFrio ? "Ficar em casa" : "Sair!!!"; 11 | print(resultado); 12 | print(estaChovendo && estaFrio ? "Azarado!" : "Sortudo!"); 13 | } -------------------------------------------------------------------------------- /fundamentos/primeiro.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | print('Olá Dart!'); 4 | print("Até o próximo exercício!!!"); 5 | 6 | { 7 | ; 8 | ; 9 | ; 10 | } 11 | 12 | print('Fim!'); 13 | } -------------------------------------------------------------------------------- /fundamentos/tipos_basicos_1.dart: -------------------------------------------------------------------------------- 1 | /* 2 | - Números (int e double) 3 | - String (String) 4 | - Booleano (bool) 5 | - dynamic 6 | */ 7 | 8 | main() { 9 | int n1 = 3; 10 | double n2 = (-5.67).abs(); 11 | double n3 = double.parse("12.765"); 12 | num n4 = 6; 13 | 14 | print(n1.abs() + n2 + n3 + n4); 15 | 16 | n4 = 6.7; 17 | print(n1.abs() + n2 + n3 + n4); 18 | 19 | String s1 = "Bom"; 20 | String s2 = " dia"; 21 | 22 | print(s1 + s2.toUpperCase() + "!!!"); 23 | 24 | bool estaChovendo = true; 25 | bool muitoFrio = false; 26 | 27 | print(estaChovendo && muitoFrio); 28 | 29 | dynamic x = "Um texto bem legal"; 30 | print(x); 31 | 32 | x = 123; 33 | print(x); 34 | 35 | x = false; 36 | print(x); 37 | 38 | var y = "Outro texto bem legal!"; 39 | // y = 123; 40 | print(y); 41 | } -------------------------------------------------------------------------------- /fundamentos/tipos_basicos_2.dart: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | - List 4 | - Set 5 | - Map 6 | */ 7 | main() { 8 | 9 | // List 10 | var aprovados = ['Ana', 'Carlos', 'Daniel', 'Rafael']; 11 | aprovados.add('Daniel'); 12 | print(aprovados is List); 13 | print(aprovados); 14 | print(aprovados.elementAt(2)); 15 | print(aprovados[0]); 16 | print(aprovados.length); 17 | 18 | var telefones = { 19 | 'João': '+55 (11) 98765-4321', 20 | 'Maria': '+55 (21) 12345-6789', 21 | 'Pedro': '+55 (85) 45455-8989', 22 | 'João': '+55 (11) 77777-7777', 23 | }; 24 | 25 | print(telefones is Map); 26 | print(telefones); 27 | print(telefones['João']); 28 | print(telefones.length); 29 | print(telefones.keys); 30 | print(telefones.values); 31 | print(telefones.entries); 32 | 33 | var times = {'Vasco', 'Flamengo', 'Fortaleza', 'São Paulo'}; 34 | print(times is Set); 35 | times.add('Palmeiras'); 36 | times.add('Palmeiras'); 37 | times.add('Palmeiras'); 38 | print(times.length); 39 | print(times.contains('Vasco')); 40 | print(times.first); 41 | print(times.last); 42 | print(times); 43 | } -------------------------------------------------------------------------------- /fundamentos/variaveis_1.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | int a = 2; 4 | double b = 3.1314; 5 | b = 3.1415; 6 | 7 | print(a * b); 8 | print(1 + 2 * 4); 9 | } -------------------------------------------------------------------------------- /fundamentos/variaveis_2.dart: -------------------------------------------------------------------------------- 1 | 2 | main() { 3 | var n1 = 2; 4 | var n2 = 4.56; 5 | var t1 = "Texto"; 6 | // t1 = 3; 7 | 8 | print(n1 + n2); 9 | 10 | print(n1.runtimeType); 11 | print(n2.runtimeType); 12 | print(t1.runtimeType); 13 | 14 | print(n1 is int); 15 | print(n1 is String); 16 | } -------------------------------------------------------------------------------- /oo/modelo/carro.dart: -------------------------------------------------------------------------------- 1 | class Carro { 2 | final int velocidadeMaxima; 3 | int _velocidadeAtual = 0; 4 | 5 | Carro([this.velocidadeMaxima = 200]); 6 | 7 | int get velocidadeAtual { 8 | return this._velocidadeAtual; 9 | } 10 | 11 | void set velocidadeAtual(int novaVelocidade) { 12 | bool deltaValido = (_velocidadeAtual - novaVelocidade).abs() <= 5; 13 | if(deltaValido && novaVelocidade >= 0) { 14 | this._velocidadeAtual = novaVelocidade; 15 | } 16 | } 17 | 18 | int acelerar() { 19 | if(_velocidadeAtual + 5 >= velocidadeMaxima) { 20 | _velocidadeAtual = velocidadeMaxima; 21 | } else { 22 | _velocidadeAtual += 5; 23 | } 24 | return _velocidadeAtual; 25 | } 26 | 27 | int frear() { 28 | if(_velocidadeAtual - 5 <= 0) { 29 | _velocidadeAtual = 0; 30 | } else { 31 | _velocidadeAtual -= 5; 32 | } 33 | return _velocidadeAtual; 34 | } 35 | 36 | bool estaNoLimite() { 37 | return _velocidadeAtual == velocidadeMaxima; 38 | } 39 | 40 | bool estaParado() { 41 | return _velocidadeAtual == 0; 42 | } 43 | } -------------------------------------------------------------------------------- /oo/modelo/cliente.dart: -------------------------------------------------------------------------------- 1 | class Cliente { 2 | String nome; 3 | String cpf; 4 | 5 | Cliente({this.nome, this.cpf}); 6 | } -------------------------------------------------------------------------------- /oo/modelo/data.dart: -------------------------------------------------------------------------------- 1 | class Data { 2 | int dia; 3 | int mes; 4 | int ano; 5 | 6 | // Data(int dia, int mes, int ano) { 7 | // this.dia = dia; 8 | // this.mes = mes; 9 | // this.ano = ano; 10 | // } 11 | 12 | Data([this.dia = 1, this.mes = 1, this.ano = 1970]); 13 | 14 | // Named Constructors 15 | Data.com({this.dia = 1, this.mes = 1, this.ano = 1970}); 16 | Data.ultimoDiaDoAno(this.ano) { 17 | dia = 31; 18 | mes = 12; 19 | } 20 | 21 | String obterFormatada() { 22 | return "$dia/$mes/$ano"; 23 | } 24 | 25 | String toString() { 26 | return obterFormatada(); 27 | } 28 | } -------------------------------------------------------------------------------- /oo/modelo/produto.dart: -------------------------------------------------------------------------------- 1 | class Produto { 2 | int codigo; 3 | String nome; 4 | double preco; 5 | double desconto; 6 | 7 | Produto({this.codigo, this.nome, this.preco, this.desconto = 0}); 8 | 9 | double get precoComDesconto { 10 | return (1 - desconto) * preco; 11 | } 12 | } -------------------------------------------------------------------------------- /oo/modelo/venda.dart: -------------------------------------------------------------------------------- 1 | import './cliente.dart'; 2 | import './venda_item.dart'; 3 | 4 | class Venda { 5 | Cliente cliente; 6 | List itens; 7 | 8 | Venda({this.cliente, this.itens = const []}); 9 | 10 | double get valorTotal { 11 | return itens 12 | .map((item) => item.preco * item.quantidade) 13 | .reduce((t, a) => t + a); 14 | } 15 | } -------------------------------------------------------------------------------- /oo/modelo/venda_item.dart: -------------------------------------------------------------------------------- 1 | import './produto.dart'; 2 | 3 | class VendaItem { 4 | Produto produto; 5 | int quantidade; 6 | double _preco; 7 | 8 | VendaItem({this.produto, this.quantidade = 1}); 9 | 10 | double get preco { 11 | if(produto != null && _preco == null) { 12 | _preco = produto.precoComDesconto; 13 | } 14 | return _preco; 15 | } 16 | 17 | void set preco(double novoPreco) { 18 | if(novoPreco > 0) { 19 | _preco = novoPreco; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /oo/teste/teste_carro.dart: -------------------------------------------------------------------------------- 1 | import '../modelo/carro.dart'; 2 | 3 | main() { 4 | var c1 = new Carro(320); 5 | 6 | while(!c1.estaNoLimite()) { 7 | print("A velocidade atual é ${c1.acelerar()} Km/h."); 8 | } 9 | 10 | print("O carro chegou no máximo com velocidade ${c1.velocidadeAtual} Km/h."); 11 | 12 | while(!c1.estaParado()) { 13 | print("A velocidade atual é ${c1.frear()} Km/h."); 14 | } 15 | 16 | c1.velocidadeAtual = 500; 17 | c1.velocidadeAtual = 3; 18 | print("O carro parou com velocidade ${c1.velocidadeAtual} Km/h."); 19 | } -------------------------------------------------------------------------------- /oo/teste/teste_data.dart: -------------------------------------------------------------------------------- 1 | import '../modelo/data.dart'; 2 | 3 | main() { 4 | var dataAniversario = new Data(3, 10, 2020); 5 | 6 | Data dataCompra = Data(1, 1, 1970); 7 | // dataCompra.dia = 23; 8 | dataCompra.mes = 12; 9 | dataCompra.ano = 2021; 10 | 11 | String d1 = dataAniversario.obterFormatada(); 12 | 13 | print("A data do aniversário é $d1"); 14 | print("A data da compra é ${dataCompra.obterFormatada()}"); 15 | 16 | print(dataCompra); 17 | print(dataCompra.toString()); 18 | 19 | print(new Data()); 20 | print(Data(31)); 21 | print(Data(31, 12)); 22 | print(Data(31, 12, 2021)); 23 | 24 | print(Data.com(ano: 2022)); 25 | 26 | var dataFinal = Data.com(dia: 12, mes: 7, ano: 2024); 27 | print("O Mickey será público em $dataFinal"); 28 | 29 | print(Data.ultimoDiaDoAno(2023)); 30 | } -------------------------------------------------------------------------------- /oo/teste/teste_venda.dart: -------------------------------------------------------------------------------- 1 | import '../modelo/cliente.dart'; 2 | import '../modelo/venda.dart'; 3 | import '../modelo/venda_item.dart'; 4 | import '../modelo/produto.dart'; 5 | 6 | main() { 7 | var vendaItem1 = VendaItem( 8 | quantidade: 30, 9 | produto: Produto( 10 | codigo: 1, 11 | nome: 'Lapis Preto', 12 | preco: 6.00, 13 | desconto: 0.5 14 | ) 15 | ); 16 | 17 | var venda = Venda( 18 | cliente: new Cliente( 19 | nome: 'Franscisco Cardoso', 20 | cpf: '123.456.789-00' 21 | ), 22 | itens: [ 23 | vendaItem1, 24 | VendaItem( 25 | quantidade: 20, 26 | produto: Produto( 27 | codigo: 123, 28 | nome: 'Caderno', 29 | preco: 20.00, 30 | desconto: 0.25 31 | ) 32 | ), 33 | VendaItem( 34 | quantidade: 100, 35 | produto: Produto( 36 | codigo: 52, 37 | nome: 'Borracha', 38 | preco: 2.00, 39 | desconto: 0.5, 40 | ) 41 | ) 42 | ] 43 | ); 44 | 45 | print("O valor total da venda é: R\$${venda.valorTotal}"); 46 | print("Nome do primeiro produto é: ${venda.itens[0].produto.nome}"); 47 | print("O CPF do cliente é: ${venda.cliente.cpf}"); 48 | } --------------------------------------------------------------------------------