Flutter发行发行版时会删除调试模式代码吗? [英] Does Flutter remove debug-mode code when compiling for release?

查看:157
本文介绍了Flutter发行发行版时会删除调试模式代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道将密码直接放置在Dart代码中是否安全,如下所示. Flutter编译发布代码时会删除代码吗?当然,我想确保代码无法反编译,以便可以提取用户名和密码.

I'm wondering whether it is safe to place passwords directly in the Dart code like below. Does Flutter remove the code when compiling it for release? Of course I want to make sure that the code cannot be decompiled such that the username and password can be extracted.

bool get isInDebugMode {
  bool inDebugMode = false;
  assert(inDebugMode = true);
  return inDebugMode;
}

if(inDebugMode){
  emailController.text = 'random@email.com';
  passwordController.text = 'secret';
}

推荐答案

inDebugMode是const值时,摇树会删除该代码.

Tree-shaking removes that code when inDebugMode is a const value.

安全"是一个很强的词,尽管即使摇晃也可以删除代码.
您可能会犯一个错误,导致摇树保留代码.
您可能会将代码提交到CVS存储库.
...

"safe" is a strong word for that though even when tree-shaking removes the code.
You could make a mistake that causes tree-shaking to retain the code.
You probably commit the code to a CVS repo.
...

您可以使用

  • 一个常量值
const bool isProduction = bool.fromEnvironment('dart.vm.product');
if(isProduction) {
  ...
}

  • flutter run -t lib/debug_main.dart

    或上述的assert方法(另请参见如何排除调试代码)

    or the assert method as mentioned (see also How to exclude debug code)

    这篇关于Flutter发行发行版时会删除调试模式代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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