prompt 0.1.7

  • Installing
  • Versions
  • 47

prompt pub package Build Status

Command-line prompting that is easy to data-drive, customize, and test.

  • Question - An information request to the user.
  • Prompt - ask (or askSync) a Question with customizable UX.
  • Top-level ask and askSync - Conveniences for using the default prompt.
  • MockPrompt - A mock prompt for testing purposes.

Barista Example


pub global activate den
den install prompt

...or the manual way.


import 'package:prompt/prompt.dart';

main() async {
  // Synchronously get a String from the user:
  var name = askSync('Name');

  // Asynchronously:
  var asyncName = await ask('Name');

  // Use [Question]s for more control:
  // Get a secret value:
  String password = askSync(new Question('Password', secret: true));

  // Get a boolean:
  bool likeCats = askSync(new Question.confirm('Like cats'));

  // Get an answer from a list of choices.
  String favoriteColor = askSync(new Question('Favorite color', allowed:
      ['red', 'green', 'blue']));

  // Get an `int` (custom validation):
  int favoriteNumber = askSync(new Question('Favorite number',
      parser: int.parse));

  // Make a function with prompting logic testable by passing it a prompt.
  // [prompt] is the default prompt.
  var sum = add3(prompt);

  // If you use [ask] anywhere, you must close stdin when done.

num add3(Prompt prompt) {
  var confident = prompt.askSync(Add3Questions.confident);
  if (!confident) {
    print('No sum for you!');
    return null;
  num getNum() => prompt.askSync(Add3Questions.addend);
  return getNum() + getNum() + getNum();

class Add3Questions {
  static final confident = new Question.confirm('Do you think this will work');
  static final addend = new Question('Enter a number', parser: num.parse);


import 'package:mock/mock.dart';
import 'package:prompt/testing.dart';
import 'package:unittest/unittest.dart';

import 'basic.dart';

main() {
  group('add3', () {
    test('should not allow doubters to ask any furthers questions', () {
      var mockPrompt = new MockPrompt((question) {
        if (question == Add3Questions.confident) return false;
        if (question == Add3Questions.addend) throw 'Asked doubter for addends';
        throw 'Unrecognized question';

      var sum = add3(mockPrompt);

      expect(sum, isNull);

    test('should calculate sum for believers', () {
      var mockPrompt = new MockPrompt((question) {
        if (question == Add3Questions.confident) return true;
        if (question == Add3Questions.addend) return 5;
        throw 'Unrecognized question';

      var sum = add3(mockPrompt);

      expect(sum, 15);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  prompt: "^0.1.7"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:prompt/prompt.dart';
Version Uploaded Documentation Archive
0.1.7 Feb 9, 2015 Go to the documentation of prompt 0.1.7 Download prompt 0.1.7 archive
0.1.6 Feb 9, 2015 Go to the documentation of prompt 0.1.6 Download prompt 0.1.6 archive
0.1.5 Feb 5, 2015 Go to the documentation of prompt 0.1.5 Download prompt 0.1.5 archive
0.1.4 Jan 27, 2015 Go to the documentation of prompt 0.1.4 Download prompt 0.1.4 archive
0.1.3 Jan 15, 2015 Go to the documentation of prompt 0.1.3 Download prompt 0.1.3 archive
0.1.2 Dec 4, 2014 Go to the documentation of prompt 0.1.2 Download prompt 0.1.2 archive
0.1.1 Dec 2, 2014 Go to the documentation of prompt 0.1.1 Download prompt 0.1.1 archive
0.1.0 Nov 26, 2014 Go to the documentation of prompt 0.1.0 Download prompt 0.1.0 archive


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
39 / 100
Code health derived from static analysis. [more]
92 / 100
Reflects how tidy and up-to-date the package is. [more]
0 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, other

Primary library: package:prompt/prompt.dart with components: io.


  • Maintain

    Changelog entries help clients to follow the progress in your code.

  • Package is too old.

    The package was released more than two years ago.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 error 9 hints.

    Strong-mode analysis of lib/testing.dart failed with the following error:

    line: 48 col: 9
    The method '_mockAsk' isn't defined for the class 'MockPrompt'.

    Run dartfmt to format lib/prompt.dart.

    Similar analysis of the following files failed:

    • lib/src/prompt.dart (hint)
    • lib/src/question.dart (hint)
    • lib/src/stdio.dart (hint)
    • lib/src/theme.dart (hint)
    • lib/src/util.dart (hint)
  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use prompt.dart.


Package Constraint Resolved Available
Direct dependencies
ansicolor >=0.0.9 <0.1.0 0.0.9 0.1.0
mock >=0.11.0 <0.12.0 0.11.0+4 0.12.0
supports_color >=0.1.1 <0.2.0 0.1.1
when >=0.2.0 <0.3.0 0.2.0
Transitive dependencies
path 1.6.1
stack_trace 1.9.2
Dev dependencies
unittest >=0.11.0 <0.12.0 0.11.7 0.12.4+1