dart_inquirer 1.0.0 copy "dart_inquirer: ^1.0.0" to clipboard
dart_inquirer: ^1.0.0 copied to clipboard

This library makes developing interacive Prompts in Dart easy and fun

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.

2
likes
5
points
28
downloads

Publisher

unverified uploader

Weekly Downloads

This library makes developing interacive Prompts in Dart easy and fun

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

console

More

Packages that depend on dart_inquirer