Nick
Nick

Reputation: 4483

How to write QuizApp using Dart Command-Line Apps?

I need to write QuizApp using Dart Command-Line Apps. There is a some example from Dartlang.org but all of the related 2013 which is very old. I am using Dart 2 and I need to write a quiz app.

I need to know how to use stdin, stdout, listen and subscription so the app doesn't quit after 1 enter.

How to write QuizApp using Dart Command-Line Apps

Upvotes: 0

Views: 200

Answers (1)

julemand101
julemand101

Reputation: 31209

You don't really need any use of subscription for a simple quiz command-line application. You only need to use stdin and stdout from the dart:io package since the application does wait for input when you are using 'stdin.readLineSync()'.

I don't want to make you homework so I am only going to give a small example:

import 'dart:io';

main() {
  while(true) {
    stdout.writeln('Are you OK? (Yes/No)');
    if (stdin.readLineSync().toLowerCase() == 'yes') {
      stdout.writeln('Then stop trouble me!');
      return;
    } else {
      stdout.write('Let me ask again! ');
    }
  }
}

Upvotes: 2

Related Questions