addQuestion method
void
addQuestion(
- dynamic pQuestion,
- dynamic key, {
- bool isBoolean = false,
- dynamic isList = false,
- 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);
}
}