askYesNo static method

Future<bool> askYesNo(
  1. String question, {
  2. bool defaultValue = true,
  3. String? fromStep,
})

Yes/No prompt with an extra "Back" option. Throws BackNavigation when the user picks the third option.

Implementation

static Future<bool> askYesNo(
  String question, {
  bool defaultValue = true,
  String? fromStep,
}) async {
  if (PromptEnvironment.useSimplePrompts) {
    return _askSimpleYesNoOrBack(
      question,
      defaultValue: defaultValue,
      fromStep: fromStep,
    );
  }
  try {
    final int choice = Select(
      prompt: '$question  (← Back to step back)',
      options: <String>['Yes', 'No', backOptionLabel],
      initialIndex: defaultValue ? 0 : 1,
    ).interact();
    switch (choice) {
      case 0:
        return true;
      case 1:
        return false;
      case 2:
        throw BackNavigation(fromStep: fromStep);
      default:
        return defaultValue;
    }
  } on BackNavigation {
    rethrow;
  } on Object {
    return _askSimpleYesNoOrBack(
      question,
      defaultValue: defaultValue,
      fromStep: fromStep,
    );
  }
}