在运行时检测应用程序是否处于发布模式
Detect during runtime whether the application is in release mode or not
我的 Dart 应用程序中有大量测试和调试内容,我想确保在使用 pub 构建发布版本时禁用这些内容。
是否有常量或其他方法来检查应用程序的当前 运行 版本是否为发布版本?
示例:
if (!IS_BUILD) {
performAutomatedDummyLogin()
} else {
login();
}
assert(...);
中的代码仅在检查(开发)模式下执行。当您 运行 在发布模式下或在发布模式下构建时,不会执行此代码。
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?
我的 Dart 应用程序中有大量测试和调试内容,我想确保在使用 pub 构建发布版本时禁用这些内容。
是否有常量或其他方法来检查应用程序的当前 运行 版本是否为发布版本?
示例:
if (!IS_BUILD) {
performAutomatedDummyLogin()
} else {
login();
}
assert(...);
中的代码仅在检查(开发)模式下执行。当您 运行 在发布模式下或在发布模式下构建时,不会执行此代码。
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?