dart_inquirer

Creator: coderz1093

Last updated:

0 purchases

dart_inquirer Image
dart_inquirer Images
Add to Cart

Description:

dart inquirer

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'} πŸ––'));
}
copied to clipboard
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 🎊");
}
copied to clipboard
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 🌎");
}
}
copied to clipboard
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 🌎");
}
}
copied to clipboard
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 ☠");
}
copied to clipboard
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 😰");
}
copied to clipboard
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);
}
copied to clipboard
[1] A
[2] B
[3] C
[βœ“] Select a letter : 2
[βœ“] Is this the letter you want ? (Y/n) y
{
first : B
second : true
}

copied to clipboard
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'} πŸ˜›");
}
copied to clipboard
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('='));
}
copied to clipboard
Features and bugs #
Please file feature requests and bugs at the issue tracker.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.