5

I got a bunch of tests and debug stuff in my Dart application and I would like to make sure these kind of things are disabled when I build a release version with pub.

Is there any constant or some other way to check if the current running version of the application is a release build or not?

Example:

if (!IS_BUILD) {
   performAutomatedDummyLogin()
} else {
   login();
}
Basic Coder
  • 10,882
  • 6
  • 42
  • 75

1 Answers1

8

Code in assert(...); is only executed in checked (development) mode. When you run in release mode or build in release mode this code isn't executed.

bool isRelease = true;
assert(() {
  isRelease = false;
  return true;
});

if(isRelease) {
 ...
} 

see also

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • 2
    If you change the boolean to be `isChecked`, you can make it shorter: `bool isChecked = false; assert((isChecked = true));`. But then, you can still avoid the extra function syntax for `isRelease` by doing `assert(!(isRelease = false))`; – lrn Apr 13 '15 at 07:55
  • 1
    Right, I tried to make it obvious that the expression needs to return `true`. – Günter Zöchbauer Apr 13 '15 at 07:58
  • 2
    Pedagogical reasons is an excellent argument, so take my comment as extra hints for those of us to like to optimization for size :) – lrn Apr 13 '15 at 08:12