getBool function

bool getBool(
  1. String message, {
  2. bool defaultsTo = false,
  3. bool appendYesNo = true,
  4. bool color = true,
  5. bool chevron = true,
  6. bool conceal = false,
  7. @deprecated bool colon = true,
  8. AnsiCode inputColor = cyan,
})

Presents a yes/no prompt to the user.

If appendYesNo is true, then a (y/n), (Y/n) or (y/N) is appended to the message, depending on its value.

color, inputColor, conceal, and chevron are forwarded to get.

Implementation

bool getBool(String message,
    {bool defaultsTo = false,
    bool appendYesNo = true,
    bool color = true,
    bool chevron = true,
    bool conceal = false,
    @deprecated bool colon = true,
    AnsiCode inputColor = cyan}) {
  if (appendYesNo) {
    message +=
        // ignore: unnecessary_null_comparison
        defaultsTo == null ? ' (y/n)' : (defaultsTo ? ' (Y/n)' : ' (y/N)');
  }
  var result = get(
    message,
    color: color,
    inputColor: inputColor,
    conceal: conceal,
    chevron: chevron && colon,
    validate: (s) {
      s = s.trim().toLowerCase();
      return (s.isEmpty) || s.startsWith('y') || s.startsWith('n');
    },
  );
  result = result.toLowerCase();

  if (result.isEmpty) {
    return defaultsTo;
  } else if (result == 'y') return true;
  return false;
}