Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 347 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call print() with colorful text to android studio console in flutter

#11
I created the screenshots and code below in [VS Code][1], but supposedly it also works in Android Studio now too:

[![enter image description here][2]][2]

```dart
void main() {
print('This is a normal message.');
printWarning('This is a warning.');
printError('This is an error.');
}

void printWarning(String text) {
print('\x1B[33m$text\x1B[0m');
}

void printError(String text) {
print('\x1B[31m$text\x1B[0m');
}
```

## ANSI escape code explanation

The ANSI escape code string is pretty confusing if you're not familiar with the format.

[![enter image description here][3]][3]

Here is the string to turn `Hello` red:

```
\x1B[31mHello\x1B[0m
```

And here it is again with spaces added for clarity between the parts:

```
\x1B [31m Hello \x1B [0m
```

Meaning:

- `\x1B`: ANSI escape sequence starting marker
- `[31m`: Escape sequence for red
- `[0m`: Escape sequence for reset (stop making the text red)

Here are the other colors:

```
Black: \x1B[30m
Red: \x1B[31m
Green: \x1B[32m
Yellow: \x1B[33m
Blue: \x1B[34m
Magenta: \x1B[35m
Cyan: \x1B[36m
White: \x1B[37m
Reset: \x1B[0m
```

Learn more from these links:

- [Build your own Command Line with ANSI escape codes][4]
- [ANSI escape code][5]


[1]:

[To see links please register here]

[2]:

[3]:

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply

#12
Improved from above code.
```dart
import 'package:flutter/foundation.dart';
import 'dart:developer' as developer;
import 'package:flutter/material.dart';

void printDebug(Object? object) {
if (kDebugMode) {
print(object);
}
}

Map<String, Stopwatch> _statusMaps = Map<String, Stopwatch>();
void startTimer(String name) {
if (kDebugMode) {
var _stopwatch = Stopwatch();
_stopwatch.start();
var status = '${name} starting\n';
_statusMaps[name] = _stopwatch;
printCustom("Timer", status);
}
}

void stopTimer(String name) {
if (kDebugMode) {
Stopwatch _stopwatch;
if (_statusMaps.containsKey(name)) {
_stopwatch = _statusMaps[name]!;
var status = '${name} executed in ${_stopwatch.elapsed}';
printCustom("Timer", status);
_statusMaps.remove(name);
}
}
}

printCustom(String name, String status, [String charater = '⚡']) {
debugPrint('\x1B[33m${"$charater $name: $status"}\x1B[0m');
}

enum DebugType { error, info, url, response, statusCode }

prettyPrint(
{required String tag,
required dynamic value,
DebugType type = DebugType.info}) {
switch (type) {
case DebugType.statusCode:
{
debugPrint('\x1B[33m${"💎 STATUS CODE $tag: $value"}\x1B[0m');
break;
}
case DebugType.info:
{
debugPrint('\x1B[32m${"⚡ INFO $tag: $value"}\x1B[0m');
break;
}
case DebugType.error:
{
debugPrint('\x1B[31m${"🚨 ERROR $tag: $value"}\x1B[0m');
break;
}
case DebugType.response:
{
debugPrint('\x1B[36m${"💡 RESPONSE $tag: $value"}\x1B[0m');
break;
}
case DebugType.url:
{
debugPrint('\x1B[34m${"📌 URL $tag: $value"}\x1B[0m');
break;
}
}
}

```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through