Questions for the user: text, passwords, numbers, yes/no and lists.
In a terminal each prompt is live: it redraws as keys are pressed, shows
problems under the question, and ends as one ✔ question answer line.
Without a terminal (piped input) the same calls ask one typed line at a
time, and in CI (PromptMode.unattended) they take their defaults. See
PromptMode for how that is picked.
Esc or Ctrl+C throws PromptCancelled. Everything is drawn with AnsiTheme.current.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
ask(
String prompt, {String? defaultValue, bool required = true, String? validator(String answer)?, String placeholder = ''}) → String - Asks a question and gives back what the user types.
-
confirm(
String prompt, {bool? defaultValue}) → bool - Asks a yes or no question and gives back true for yes.
-
decimal(
String prompt, {double? defaultValue, double? min, double? max, double step = 1}) → double -
Asks for a number that can have decimals. Up and down change it by
step. -
grid<
T> (String prompt, List< T> options, {String format(T option)?, T? defaultOption, int? columns}) → T -
Lets the user pick one of
optionslaid out in a grid, moving in all four directions. Suits short options like sizes or regions. -
integer(
String prompt, {int? defaultValue, int? min, int? max, int step = 1}) → int -
Asks for a whole number. Up and down change it by
step. - The same as select, kept for code written before it.
-
multiline(
String prompt, {String defaultValue = '', bool required = false}) → String - Asks for text over several lines. Ctrl+D finishes.
-
multiSelect<
T> (String prompt, List< T> options, {String format(T option)?, String note(T option)?, Iterable<T> selected = const [], int min = 0, int? max, int? pageSize}) → List<T> -
Lets the user tick any number of
options, and gives back the ticked ones in list order. -
password(
String prompt, {String? mask, bool required = true, String? validator(String answer)?}) → String - Asks for a password, showing a mask for each typed character.
-
search<
T> (String prompt, List< T> options, {String format(T option)?, String note(T option)?, T? defaultOption, int? pageSize}) → T -
Lets the user pick one of
optionsby typing to filter them, like a command palette. -
select<
T> (String prompt, List< T> options, {String format(T option)?, String note(T option)?, T? defaultOption, int? pageSize}) → T -
Lets the user pick one of
optionsand gives back the one they picked. - Asks for a list of short words, like labels, shown as tags while typed.
-
toggles(
String prompt, Map< String, bool> switches, {String note(String name)?}) → Map<String, bool> - Shows a list of on/off switches and gives back each name with its state.