confirm method

Future<bool> confirm(
  1. String question, {
  2. bool? defaultValue,
})

Asks question, answered yes (true) or no (false); defaultValue is what Enter, or an empty line, answers.

Without a default nothing is agreed to on anybody's behalf: Enter answers nothing until yes or no is chosen, and where nobody can answer it throws PromptAnswerRequiredException, so a question that changes something wants a --yes flag for unattended runs.

  • CliMode.interactive: the question and the answers of a ConfirmInput; y and n answer, Left and Right move the highlight, Enter answers it. ✔ question yes is committed.
  • CliMode.plain: ? question [Y/n] , asked again until the answer is y, yes, n or no in any case, or empty with a default.
  • CliMode.nonInteractive: defaultValue, written as ? question yes.

Ctrl+C, Ctrl+D and the end of input leave it as they leave prompt.

if (await Cli.current.confirm('Proceed?', defaultValue: true)) {
  Cli.current.info('Proceeding.');
}

Implementation

Future<bool> confirm(String question, {bool? defaultValue}) =>
    _prompter.confirm(question, defaultValue: defaultValue);