dart_inquirer 1.0.0

Dart Inquirer #

This library makes developing interacive Prompts in Dart easy πŸ‘ and pretty 😍

!WARNING! : This project is still under development, tips and tricks are always appreaciated

Usage #

A simple usage example:

import 'package:dart_inquirer/dart_inquirer.dart';

main() {
  List questions = [
    InputQuestion('name', 'Whats your beautiful name ?')
  ];

  Prompt prompt = Prompt(questions);

  prompt.execute().then((Map answers) => print('πŸŽ‰ Hello ${(answers["name"] as String).isNotEmpty ? answers["name"] : 'World'} πŸ––'));
}

Prompt types #

Dart Inquirer is my first Project so I didn't implement a lot of Question Types, but the most important ones

InputQuestion #

The InputQuestion can handle simple Inputs and returns a String

import 'package:dart_inquirer/dart_inquirer.dart';

main() async {
  List<Question> questions = [
    InputQuestion('name', 'Whats your beautiful name ?')
  ];

  Prompt prompt = Prompt(questions);

  var name = (await prompt.execute())["name"];

  print("βœ‹ Hello $name 🎊");
}

ConfirmQuestion #

Every project needs some kind of user confirmation, so for that reason we have the ConfirmQuestion

import 'package:dart_inquirer/dart_inquirer.dart';

main() {
  List<Question> questions = [
    ConfirmQuestion('alien', 'Are you a citizen of Earth ?')
  ];

  Prompt prompt = Prompt(questions);

  if (!(await prompt.execute())["alien"]){
    print("πŸ‘½πŸ–– Please don't experiment with us πŸ‘ΎπŸ„");
  }else {
    print("🌍 Earthlings are always welcome 🌎");
  }
}

Also you can change either if the Y or N is preffered

import 'package:dart_inquirer/dart_inquirer.dart';

main() async{
  List<Question> questions = [
    // ⬇⬇⬇ CHANGED THIS LINE ⬇⬇⬇
    ConfirmQuestion('alien', 'Are you a citizen of Earth ?', preferN: true)
  //ConfirmQuestion('alien', 'Are you a citizen of Earth ?') ⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆
  ];

  Prompt prompt = Prompt(questions);

  if (!(await prompt.execute())["alien"]){
    print("πŸ‘½πŸ–– Please don't experiment with us πŸ‘ΎπŸ„");
  }else {
    print("🌍 Earthlings are always welcome 🌎");
  }
}

PasswordQuestion #

Sometimes your users will need to specify some super secret thing 😜 so for that purpose we have the password question. It will protect others from just seeing the Input

!Warning! : This is not very secure

import 'package:dart_inquirer/dart_inquirer.dart';

main() async {
  List<Question> questions = [
    PasswordQuestion('secret', 'Whats your biggest fear ?')
  ];

  Prompt prompt = Prompt(questions);

  String fear = (await prompt.execute())["secret"];

  print("πŸ‘» Man this ${'*'*fear.length} is very scary ☠");
}

ListQuestion #

If you want your users to select an option you can do that by simply using a ListQuestion

import 'package:dart_inquirer/dart_inquirer.dart';

main() async {
  List<Question> questions = [
    ListQuestion('hate', 'What do you like least on your Pizza', ['Pineapple', 'Ham', 'Tomatoes'])
  ];

  Prompt prompt = Prompt(questions);

  String hate = (await prompt.execute())["hate"];

  print("πŸ• I wouldn't eat $hate as well 😰");
}

Helpers #

I have implemented some helpers

Pretty json formatting #

import 'package:dart_inquirer/dart_inquirer.dart';

main() async {
  List<Question> questions = [
    ListQuestion('first', 'Select a letter', ['A', 'B', 'C']),
    ConfirmQuestion('second', 'Is this the letter you want ?')
  ];

  Map answers = {};
  Prompt prompt = Prompt(questions);

  while (answers["second"] != true) {
    answers = await prompt.execute();
  }

  prettyPrintJson(answers);
}
[1] A
[2] B
[3] C
[βœ“] Select a letter : 2
[βœ“] Is this the letter you want ?  (Y/n) y
{
	first : B
	second : true
}

Skipping Questions #

You can skip a question if you don't want to let it execute, just specify a conditional function

import 'package:dart_inquirer/dart_inquirer.dart';

main() async{
  List<Question> questions = [
    ConfirmQuestion('confirm', 'Do you want to type your name ?'),
    InputQuestion('name', 'Username:', skipIf: (Map ctx) => ctx["confirm"] == false)
  ];

  Map answers = await Prompt(questions).execute();

  print("😸 Hello ${(answers["name"] as String).isNotEmpty ? answers["name"] : 'World'} πŸ˜›");
}

Sepperator #

Maybe you want to put down a nice Sepperator ... then this here is for you

import 'package:dart_inquirer/dart_inquirer.dart';

main() {
  print(Seperator());
  print(Seperator('='));
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

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


dependencies:
  dart_inquirer: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:dart_inquirer/dart_inquirer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

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

Health suggestions

Format lib/dart_inquirer.dart.

Run dartfmt to format lib/dart_inquirer.dart.

Format lib/src/prompt.dart.

Run dartfmt to format lib/src/prompt.dart.

Format lib/src/prompts/confirm.dart.

Run dartfmt to format lib/src/prompts/confirm.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/prompts/input.dart (Run dartfmt to format lib/src/prompts/input.dart.)
  • lib/src/prompts/list.dart (Run dartfmt to format lib/src/prompts/list.dart.)
  • lib/src/prompts/password.dart (Run dartfmt to format lib/src/prompts/password.dart.)
  • lib/src/question.dart (Run dartfmt to format lib/src/question.dart.)
  • lib/src/seperator.dart (Run dartfmt to format lib/src/seperator.dart.)

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/Sm03leBr00t/DartInquirer was unreachable.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and dart_inquirer.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
console ^3.1.0 3.1.0
Transitive dependencies
vector_math 2.0.8
Dev dependencies
pedantic ^1.0.0
test ^1.0.0

Admin