I have a section of my flutter/dart code that I want to include only when building for debugging. I could create a custom define like this:
import 'dart:developer';
void main() {
#if DEBUG
log('This message will only be printed in debug mode');
#endif
// Other code that runs in both debug and release modes
}
…and use it like this…
flutter build apk --dart-define=DEBUG=true
But, it would be better if I didn’t have to remember to set that flag. Is there a cleaner way to do this?
2
Answers
The KDebugmode Variable might be what you are looking for
KdebugMode
The flag mentioned by @nlykk12 is the one you need – it works out of the box.
In your example it would be:
To build it in debug mode you would only need:
To make sure you’re building in a release mode:
* (the
--release
and--debug
) flags work for other distributions, not onlyapk
.