prompt method

Future<String> prompt(
  1. String question, {
  2. String? defaultValue,
  3. bool hidden = false,
  4. String? validate(
    1. String answer
    )?,
  5. FutureOr<List<String>> suggest(
    1. String typed
    )?,
  6. String? placeholder,
})

Asks question and answers the line typed, defaultValue for an empty one (the empty string without one).

validate refuses an answer with a message, which is shown, and the question is asked again. With hidden the answer is not shown as it is typed: masked with one * per character in the interactive mode, not echoed in the plain one; written back, it reads ****** whatever its length.

How it asks follows the mode:

Prompts are asked one at a time: one asked while another is waits for it.

final name = await Cli.current.prompt(
  'Project name?',
  defaultValue: 'my_app',
  validate: (name) => RegExp(r'^[a-z_]+$').hasMatch(name)
      ? null
      : 'lowercase letters and _ only',
);

Implementation

Future<String> prompt(
  String question, {
  String? defaultValue,
  bool hidden = false,
  String? Function(String answer)? validate,
  FutureOr<List<String>> Function(String typed)? suggest,
  String? placeholder,
}) => _prompter.prompt(
  question,
  defaultValue: defaultValue,
  hidden: hidden,
  validate: validate,
  suggest: suggest,
  placeholder: placeholder,
);