addQuestion method

void addQuestion(
  1. dynamic pQuestion,
  2. dynamic key, {
  3. bool isBoolean = false,
  4. dynamic isList = false,
  5. dynamic isMessage = false,
})

This method is another way of adding questions after instantiating CliDialog. Pass isBoolean, isList, or isMessage as a named argument to indicate the type of question you are adding.

final dialog = CliDialog();
// Plain text question:
dialog.addQuestion('What is your name?', 'name');
// List/multiple-choice question — the first positional arg is the
// {question, options} map, the second is the answer key:
dialog.addQuestion(
  {'question': 'How are you?', 'options': ['Good', 'Not so good']},
  'mood',
  isList: true,
);

Implementation

void addQuestion(
  pQuestion,
  key, {
  bool isBoolean = false,
  isList = false,
  isMessage = false,
}) {
  if ((isBoolean ? 1 : 0) + (isList ? 1 : 0) + (isMessage ? 1 : 0) > 1) {
    throw ArgumentError(
      'A question can not have more than one boolean qualifier.',
    );
  }
  final newItem = [pQuestion, key];
  if (isBoolean) {
    booleanQuestions!.add(newItem);
  } else if (isList) {
    listQuestions!.add(newItem);
  } else if (isMessage) {
    messages!.add(newItem);
  } else {
    questions!.add(newItem);
  }
}