在运行时检测应用程序是否处于发布模式 [英] Detect during runtime whether the application is in release mode or not

查看:61
本文介绍了在运行时检测应用程序是否处于发布模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Dart应用程序中进行了大量测试和调试工作,并且我想确保在与pub构建发行版时禁用这些事情。

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?

示例:

if (!IS_BUILD) {
   performAutomatedDummyLogin()
} else {
   login();
}


推荐答案

<$ c $中的代码c> assert(...); 仅在检查(开发)模式下执行。在发布模式下运行或在发布模式下构建时,不会执行此代码。

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) {
 ...
} 

另请参见

  • Dart: How to use different settings in debug and production mode?
  • How to achieve precompiler directive like functionality
  • Is there a compiler preprocessor in Dart?

这篇关于在运行时检测应用程序是否处于发布模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆