Ride Sun
Ride Sun

Reputation: 2323

How can I print colored debug messages with Flutter / Dart to show colored Android Studio console output?

How can I print colored debug messages with Flutter/Dart to show colored Android Studio console/logcat output? There are many dart packages that provide the escape characters for colored output but the Android Studio simply does not show them.

Some of them are: https://github.com/iamsalnikov/colorize or https://pub.dev/packages/ansicolor

Or simply some escape characters should work as well:

   print('\x1B[94m $text \x1B[0m');

These messages show up like this:

 [94m [36m57 2019-10-18 16:18:55.694098 FINE ui.app.dart: initial route = null[0m [0m

My question is, can I exchange the console to see the escape characters? Or just any other way?

Upvotes: 1

Views: 2919

Answers (1)

harm
harm

Reputation: 10385

I don't believe this is possible at this point. How this works exactly is still a bit unclear to me but it hinges on the supportsAnsiEscapes method. This outputs false when running in Android Studio:

import 'dart:io' as io;
print(io.stdout.supportsAnsiEscapes);

Escape sequences are then simply ignored.

Note that even if this call would return true Android Studio only supports a limited subset of ANSI colors: https://youtrack.jetbrains.com/issue/IDEA-137065

Upvotes: 1

Related Questions