Solved: switching between debugging and production mode

Question

Asked by mrs.tat on March 19, 2019 (source).

As a fast way of debugging app while developing is writing a statement like:

print($data)

is there is a way to stop printing when switching to production mode so it will not affect the performance of the app?

a boolean as a switch for example?

Answer

Question answered by Rémi R (source).

You can use debugPrint instead of print for dev only logging

debugPrint(data)

debugPrint implementation can be made to change between environment. For instance in your main you can do:

void main() {
  bool isInRelease = true;

  assert(() { isInRelease = false; return true }());

  if (isInRelease) {
    debugPrint = (String message, { int wrapWidth }) {}
  }
}

This will replace the implementation of debugPrint with something that does nothing in release

DART FLUTTER
SHARE: