Skip to content

Instantly share code, notes, and snippets.

@elbeicktalat
Last active November 21, 2021 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbeicktalat/0250542e71993452f98e23b2f20ebbc6 to your computer and use it in GitHub Desktop.
Save elbeicktalat/0250542e71993452f98e23b2f20ebbc6 to your computer and use it in GitHub Desktop.
How to call print( ); with colorful text to console in dart.
class Colors {
static String black(String text) {
return '\x1B[30m$text\x1B[0m';
}
static String red(String text) {
return '\x1B[31m$text\x1B[0m';
}
static String green(String text) {
return '\x1B[32m$text\x1B[0m';
}
static String Yellow(String text) {
return '\x1B[33m$text\x1B[0m';
}
static String blue(String text) {
return '\x1B[34m$text\x1B[0m';
}
static String magenta(String text) {
return '\x1B[35m$text\x1B[0m';
}
static String cyan(String text) {
return '\x1B[36m$text\x1B[0m';
}
static String white(String text) {
return '\x1B[37m$text\x1B[0m';
}
}
// with colors method
void main(List<String> args) {
print('your name: <${Colors.blue(args[1])}> your surname:<${Colors.green(args[2])}>');
}
//without colors method
void main(List<String> args) {
print('your name: \x1B[34m<${args[1]}>\x1B[0m your surname:\x1B[32m<${args[2]}>\x1B[0m'');
}
// as you see it is too easy to understanda whats happend in the first example.
// if you have any othre class called Colors you can do like so:
import'colors.dart' as console;
class Colors{}
void main(List<String> args) {
print('your name: <${console.Colors.blue(args[1])}> your surname:<${console.Colors.green(args[2])}>');
}
// I hope this was clear for you Thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment