Created
April 4, 2019 23:33
-
-
Save jacobaraujo7/939320b7589a7f2a25d18c5290ecc0e7 to your computer and use it in GitHub Desktop.
carrinho_compras.dart
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
import "dart:io"; | |
List<String> produtos = []; | |
main() { | |
bool condicao = true; | |
while (condicao) { | |
print("==== ADICIONE UM PRODUTO ===="); | |
String text = stdin.readLineSync(); | |
if (text == "sair") { | |
print("==== TERMINOU O PROGRAMA ===="); | |
condicao = false; | |
} else if (text == "imprimir") { | |
imprimir(); | |
} else if (text == "remover") { | |
remover(); | |
} else { | |
produtos.add(text); | |
print("\x1B[2J\x1B[0;0H"); | |
} | |
} | |
} | |
imprimir() { | |
for (var i = 0; i < produtos.length; i++) { | |
print("ITEM $i - ${produtos[i]}"); | |
} | |
} | |
remover() { | |
print("==== qual item deseja remover?"); | |
imprimir(); | |
int item = int.parse(stdin.readLineSync()); | |
produtos.removeAt(item); | |
print("==== ITEM REMOVIDO"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ao pessoal que não está conseguindo. Muito provável ser a versão que está usando. Pra resolver basta colocar um "!" no codigo.
Este vídeo explica melhor https://www.youtube.com/watch?v=LulvhhDiqQw