There is some confusion when to use print
and debugPrint
, so there are some statements which may be false, and which should be clearified:
When using the direct print
method then it will bring a lot of a trash into production, will not it?
When using the debugPrint
method then it will print only while developing, or it will print also in production?
When I generate a release file (apk), will not it delete all the print
calls to optimize the app and reduce the release file size?
flutter logs
you will see the output of the print function in all applications you have installed in the phone/emulator. This means that even if the app is in release mode, it will still be printed in the terminal.debugPrint
generally is used to avoid the printing limit of each OS, if default debugPrintThrottled
callback is used. It will also print in production, but you can customize it to work only in dev mode:import "package:flutter/foundation.dart"; //allows to use kReleaseMode
void main() {
if (kReleaseMode) {
debugPrint = (String? message, {int? wrapWidth}) {};
}
}
With this when the debugPrint
statements in your code called in production, it won’t be printed to the console since you gave this function an empty callback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With